python - 尝试发布到 gfycat.com 时 Python 请求给出错误 ('Connection aborted.', error("(104, 'ECONNRESET')",))
问题描述
我正在执行代码:
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
。我已经阅读了请求文档,并且确实找到了一些我修复的东西。现在我被困在这里,试图找出连接中止的原因。
解决方案
使用pfycat
import pfycat
c = pfycat.Client("client_id", "client_secret")
r = c.upload('banana.gif')
print(r)
或者:看看pfycat 是怎么做的
推荐阅读
- python - 是否可以使用 ConfigParser 获取随机值
- google-apps-script - 在 Google 表单中添加日期范围或禁用日期
- python - 如何制作时间框架集群?
- swift - SwiftUI:如何在第一次启动时显示警报
- python - 尝试使用交叉验证时出错
- flutter - 如何将不透明度应用于散点图颤动
- css - 无法将简单的 CSS 应用于有角度的材料元素
- reactjs - React Redux Axios Api Get 调用带路径参数
- javascript - 错误:在动态填充表的情况下未定义事件
- powershell - 从数组中删除重复值并将对象转换为标题大小写