我正在编写一个简短的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'

我收到以下错误:

Traceback(最近一次调用最后一次):文件“tweeter.py”,第13行,在api.update_profile_image(avatar = image)文件“/usr/lib/python2.7/dist-packages/twython/endpoints.py”,第474行,在update_profile_image中返回self.post('account / update_profile_image',params = params)文件“/usr/lib/python2.7/dist-packages/twython/api.py”,第268行,在post return self中 . 请求( endpoints ,'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-Rate-Limit-Reset'))twython.exceptions.TwythonError:Twitter API返回400(错误请求),图像参数丢失 .

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