Tweepy ошибка при размещении изображения с Reddit - PullRequest
0 голосов
/ 25 февраля 2019
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

Я не до конца понимаю, почему произошла эта ошибка. Я использовал python-twitter перед переключением наи когда я получил эту ошибку, я не понял, что это значит.

...