gpt4 book ai didi

python - 尝试通过 Python 中的 HTTPLib 将数据上传到 Parse

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:28:28 25 4
gpt4 key购买 nike

我正在尝试使用 HTTPLib 和以下代码将多个文件上传到 Parse:

        connection = httplib.HTTPSConnection('api.parse.com', 443)
connection.connect()

connection.request('POST', '/1/files/' + fileName, open(fileName, 'rb').read(), {
"X-Parse-Application-Id": "6CXB7R7Q6Z6vUVbOqAgBNeDe0bavqfc40QH58fJv",
"X-Parse-REST-API-Key": "hBDXavBbm2V4xXJX6874MfcWjB9lIrx7DFTlWTbm",
"Content-Type": "image/png"
})
result_pic = json.loads(connection.getresponse().read())
print result_pic

对于前 10 个左右的文件,它运行良好。然后突然间它坏了。首先,我无法再阅读回复 (result_pic) 向我发送异常“ResponseNotReady”。我更改了我的代码中的一些内容,现在当我尝试建立连接时,我总是会收到以下形式的解码错误:

Traceback (most recent call last):
File "/Users/apple/PycharmProjects/untitled/Angel_list_request.py", line 67, in <module>
"Content-Type": "image/png"
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 973, in request
self._send_request(method, url, body, headers)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 1007, in _send_request
self.endheaders(body)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 969, in endheaders
self._send_output(message_body)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 827, in _send_output
msg += message_body
UnicodeDecodeError: 'ascii' codec can't decode byte 0xff in position 0: ordinal not in range(128)

不知道发生了什么。有解码的东西,但我以前根本没有遇到过。

最佳答案

想通了。是fileName的unicode转换。即使 fileName 是一个字符串,我也不得不用 str(fileName) 强制转换它。现在一切正常!

关于python - 尝试通过 Python 中的 HTTPLib 将数据上传到 Parse,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32236657/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com