Python中的REST调用

Python中的REST调用,python,json,firebase,Python,Json,Firebase,我正试图编写一个脚本,将现有数据库移植到Firebase中。我的数据存储在JSON中,我想我可以直接提取JSON,然后将其作为数据发送到我的Firebase中 def Post_And_Recieve_JSON(url, data, headers): print("Compiling query...") Post_And_Recieve_JSON.url = url Post_And_Recieve_JSON.headers = headers Post_An

我正试图编写一个脚本,将现有数据库移植到Firebase中。我的数据存储在JSON中,我想我可以直接提取JSON,然后将其作为数据发送到我的Firebase中

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库解决了这个问题,可以在这里找到:

我用pip3安装它。我只是希望我可以像做其他REST调用那样做,而不需要一个新的库

full_data = []
from firebase import *
firebase = firebase.FirebaseApplication('https://secret_url.firebaseio.com/', None)

for id in id_list:
    print(str(id))
    url = 'from_url'
    try:
        result = firebase.put('/users/ ' + str(id) + '/',    data=Post_And_Recieve_JSON(url, None, headers)["payload"], name='Data')
    except:
        print('Skipping a user')

我想使用firebase python助手,但这是针对python2.7的。我需要python3的urllib和urllib.request来提取我的原始数据。