在尝试发布到gfycat.com时,Python请求提供错误('连接中止。',错误("(104,' ECONNRESET')",))

时间:2018-05-23 04:44:48

标签: python http https python-requests gfycat

我正在执行代码:

import requests

clientID = redacted
secret =redacted

filename = "temp2.gif"
datakey = '{ "title":"random title"}'

r = requests.post("https://api.gfycat.com/v1/gfycats", data = datakey)
gfyname = r.json()["gfyname"]
print(r.json())
print(gfyname)

params_ = {'client_id': clientID, 'client_secret': secret, 'grant_type': 'client_credentials'}

r = requests.post('https://api.gfycat.com/v1/oauth/token', data=str(params_))

access_token = r.json()['access_token']

headers = {'Authorization': 'Bearer {}'.format(access_token)}
print(headers)
data = {'key': gfyname}
url = "https://filedrop.gfycat.com"
files = {gfyname: open(filename, 'rb')}

r = requests.post(url, data=data, files=files, headers=headers)
print(r)

这一切都执行正常,直到最后一次request.post()调用,这是我收到错误消息的时候:

requests.exceptions.ConnectionError: ('Connection aborted.', error("(104, 'ECONNRESET')",))

我已使用gfycat api文档验证了请求端点/参数。我检查了headersaccess_token的输出。我已阅读了请求文档,我确实找到了一些我修复过的内容。现在我被困在这里,试图找出连接中止的原因。

1 个答案:

答案 0 :(得分:0)

使用pfycat

import pfycat
c = pfycat.Client("client_id", "client_secret")
r = c.upload('banana.gif')
print(r)

或者:看看pfycat does it