关于从Reddit发布图像的Tweepy错误

时间:2019-02-25 02:22:12

标签: python tweepy

import tweepy, json, requests, time, os

consumer_key = "CONSUMERKEY"
consumer_secret = "CONSUMERSECRET"
access_token_key = "ACCESSTOKEN"
access_token_secret = "ACESSTOKENSECRET"

auth = tweepy.OAuthHandler(consumer_key, consumer_key)
auth.set_access_token(access_token_key, access_token_secret)

api = tweepy.API(auth)

lastImageUrl = ""

def postMoe():
    global lastImageUrl
    with requests.get('https://www.reddit.com/r/awwnime/new.json', headers={'user-agent': 'OreganoMoeBot'}) as url:
        moeData = json.loads(url.content)['data']['children'][0]['data']
        moeImage = moeData['url']
        moeLink = "https://www.reddit.com" + moeData['permalink']
        if (moeImage != lastImageUrl):
            status = "#moe | " + moeLink
            api.update_with_media(moeImage, status=status)
            lastImageUrl = moeImage

while True:
    postMoe()
    time.sleep(3600)

好吧,所以当我尝试运行它时,出现了错误消息:

Traceback (most recent call last):
  File "C:\Users\Samuel Riggs\AppData\Local\Programs\Python\Python36\lib\site-packages\tweepy\api.py", line 1343, in _pack_image
    if os.path.getsize(filename) > (max_size * 1024):
  File "C:\Users\Samuel Riggs\AppData\Local\Programs\Python\Python36\lib\genericpath.py", line 50, in getsize
    return os.stat(filename).st_size
OSError: [WinError 123] The filename, directory name, or volume label syntax is incorrect: 'https://imgur.com/ETcqXJS'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\Samuel Riggs\Documents\Bots\MoeBot\bot.py", line 27, in <module>
    postMoe()
  File "C:\Users\Samuel Riggs\Documents\Bots\MoeBot\bot.py", line 23, in postMoe
    api.update_with_media(moeImage, status=status)
  File "C:\Users\Samuel Riggs\AppData\Local\Programs\Python\Python36\lib\site-packages\tweepy\api.py", line 220, in update_with_media
    headers, post_data = API._pack_image(filename, 3072, form_field='media[]', f=f)
  File "C:\Users\Samuel Riggs\AppData\Local\Programs\Python\Python36\lib\site-packages\tweepy\api.py", line 1346, in _pack_image
    raise TweepError('Unable to access file: %s' % e.strerror)
tweepy.error.TweepError: Unable to access file: The filename, directory name, or volume label syntax is incorrect

我不完全理解为什么会发生此错误,在切换到tweepy之前我一直使用python-twitter,当我收到此错误时,我并不真正理解它的含义。

0 个答案:

没有答案