#!/usr/bin/python
#-*-coding:utf-8-*- #指定編碼格式,python默認unicode編碼
import requests
import json
APPID = ""
APPSECRET=""
url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=APPID&secret=APPSECRET"
access_token = ''
def getToken():
# url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid="+APPID+"&secret="+APPSECRET
payload = {'grant_type': 'client_credential', 'appid': APPID, 'secret' : APPSECRET}
r = requests.get('https://api.weixin.qq.com/cgi-bin/token',payload)
# content = r.content
content = r.json()
print(content)
print(type(content))
print(r.status_code)
# getToken()
def postdata():
# url = "https://api.weixin.qq.com/tcb/databasemigrateimport?access_token=ACCESS_TOKEN"
mydata = {
'env':'xiaogushi-vakhg',
'collection_name':'qixi',
'file_path':'gushici/qixi.json',
'file_type':1,
'stop_on_error':False,
'conflict_mode': 1
}
url = "https://api.weixin.qq.com/tcb/databasemigrateimport?access_token="+access_token
headers ={'Content-Type' : 'application/json'}
r= requests.post(url,headers = headers,data=json.dumps(mydata))
print(r.content)
# postdata()
注意:
1.post的數據格式要求json
2.雲數據庫要先建立好,才能插入數據。