我想通过使用PTT(Python Twitter工具)在Twitter上发布图像。 目前,我的代码是完全是这样:如何在Python Twitter工具库中使用状态/ update_with_media?
def _TweetMedia(self, t, m):
try:
param = {'media[]', m}
self.API.statuses.update_with_media(status = t, **param)
except Exception as e:
print("Failed to tweet media, reason: %s" % e)
return False
return True
但它失败
Failed to tweet media, reason: Twitter sent status 403 for URL: 1.1/statuses/update_with_media.json
using parameters: (oauth_consumer_key=y&oauth_nonce=13911566611016743303&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1399668386&oauth_token=x&oauth_version=1.0&oauth_signature=z)
details: {"errors":[{"code":189,"message":"Error creating status."}]}
我真的不知道为什么。 我的图像是从URL中读取的,然后用base64编码。
def DownloadImg(self, uri):
try:
source = b64encode(urllib2.urlopen(uri).read())
filename = uri.split('/')[-1]
return (filename, source)
except Exception as e:
print("Failed to download %s: %s." % (uri.split()[-1], e))
return (None, None)
pass
多部分是HTTP请求的东西。 – Raito