[英]Python requests giving error ('Connection aborted.', error(“(104, 'ECONNRESET')”,)) when attempting to post to gfycat.com
I am executing the code: 我正在执行代码:
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)
It all executes fine until the very last request.post() call which is when I receive the error message: 一切执行正常,直到最后一个request.post()调用,这是我收到错误消息的时间:
requests.exceptions.ConnectionError: ('Connection aborted.', error("(104, 'ECONNRESET')",))
I have verified the requests endpoints/params with the gfycat api documentation. 我已经使用gfycat api文档验证了请求端点/参数。 I have checked the output of the
headers
and the access_token
. 我已经检查了
headers
和access_token
的输出。 I have read through the requests documentation and I did find a few things to which I fixed. 我已经阅读了请求文档,确实发现了一些我要解决的问题。 and now I am stuck here, trying to figure out why the connection is aborting.
现在我被困在这里,试图弄清连接为什么中断。
import pfycat
c = pfycat.Client("client_id", "client_secret")
r = c.upload('banana.gif')
print(r)
alternatively: look how pfycat does it 或者:看看pfycat是如何做到的
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.