我正在执行代码:
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文档验证了请求端点/参数。我检查了headers
和access_token
的输出。我已阅读了请求文档,我确实找到了一些我修复过的内容。现在我被困在这里,试图找出连接中止的原因。
答案 0 :(得分:0)
使用pfycat
import pfycat
c = pfycat.Client("client_id", "client_secret")
r = c.upload('banana.gif')
print(r)
或者:看看pfycat does it