0
我正在嘗試編寫腳本來將現有的數據庫移植到Firebase中。我的數據存儲在JSON中,我認爲我可以拉JSON,然後將其作爲數據發送到我的Firebase的POST。Python中的REST調用
def Post_And_Recieve_JSON(url, data, headers):
print("Compiling query...")
Post_And_Recieve_JSON.url = url
Post_And_Recieve_JSON.headers = headers
Post_And_Recieve_JSON.data = (data)
print("Sending request...")
request = urllib.request.Request(url=url, data=data,headers=headers)
print("Recieving response...")
response = urllib.request.urlopen(request)
print("Reading response...")
response_data = response.read()
print("Converting into usable format...")
response_data_JSON = json.loads(response_data.decode(encoding='UTF-8'))
return response_data_JSON
for all_users in existing_database:
full_data.append(Post_And_Recieve_JSON(...)
for item in full_data:
url = 'firebaseurlhere ' + item['profileId'] + '.json'
data = json.dumps(item).encode('ascii')
Post_And_Recieve_JSON(url, data, headers)
其中full_data是JSON對象的列表我已經從現有的數據庫中正確取出。
我得到 「http.client.BadStatusLine: ''」
我想使用firebase python幫手,http://ozgur.github.io/python-firebase/,但是這是爲python2.7。我需要從python3的urllib和urllib.request拉我的原始數據。 – MZA