代码之家  ›  专栏  ›  技术社区  ›  ThePeskyWabbit

Python请求在尝试发布到gfycat.com时给出错误('Connection aborted.','error('104'ECONNRESET'),))

  •  0
  • ThePeskyWabbit  · 技术社区  · 7 年前

    我正在执行代码:

    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 . 我已经阅读了请求文档,我确实找到了一些修复的地方。现在我被困在这里,想弄清楚为什么连接会中断。

    1 回复  |  直到 7 年前
        1
  •  0
  •   wotanii    7 年前

    使用 pfycat

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

    或者:看看 pfycat does it

    推荐文章