twython upload_profile_image图像参数丢失

时间:2018-06-19 05:45:59

标签: twython

我正在编写一个简短的python脚本来使用twython API:

#!/usr/bin/python
import sys
from twython import Twython
#encryption info
consumerKey = ''
consumerSecret = ''
accessToken = ''
accessTokenSecret = ''
#create instance of Twitter api
api = Twython(consumerKey, consumerSecret, accessToken, accessTokenSecret)
api.update_status(status=sys.argv)  # post a new tweet
image = open('/home/pi/Downloads/kermit.jpg', 'rb')
api.update_profile_image(avatar=image)

但是当我像下面那样运行脚本时:

sudo python tweeter.py 'i love twitter'

我收到以下错误:

  

追踪(最近一次通话):         文件" tweeter.py",第13行,in           api.update_profile_image(化身=图像)         文件" /usr/lib/python2.7/dist-packages/twython/endpoints.py",第474行,在update_profile_image中           return self.post(' account / update_profile_image',params = params)         文件" /usr/lib/python2.7/dist-packages/twython/api.py" ;,第268行,在帖子中           return self.request(endpoint,' POST',params = params,version = version)         文件" /usr/lib/python2.7/dist-packages/twython/api.py",第258行,请求中           api_call = URL)         文件" /usr/lib/python2.7/dist-packages/twython/api.py" ;,第194行,在_request中           retry_after = response.headers.get(' X-限速复位'))       twython.exceptions.TwythonError:Twitter API返回400(错误请求),图像参数丢失。

我是否将错误的参数传递给此函数?如果是这样,我如何正确地将图像作为参数传递?

0 个答案:

没有答案