0

使用 Tweepy 将背景图片上传到 Twitter 时,出现以下错误:

tweepy.error.TweepError: [{'message': '对不起,该页面不存在', 'code': 34}]

我可以通过 update_with_media 和 update_status 上传带有图像的状态,而不是 update_profile_background_image。

我正在创建一个使用 ImageDraw.Draw 在图像上放置文本的图像。正文是从现在到 2020 年选举(11 月 3 日上午 7:00)之间的时间。除了推送到 Twitter 之外,一切都按预期工作(图像创建、优化等)

这是错误和代码:

        Traceback (most recent call last):
      File "/Users/kevin/PycharmProjects/twitter_countdown_bot/main.py", line 42, in <module>
        authenticate.update_profile_background_image(header_image)
      File "/Users/kevin/PycharmProjects/twitter_countdown_bot/venv/lib/python3.8/site-packages/tweepy/api.py", line 708, in update_profile_background_image
        return bind_api(
      File "/Users/kevin/PycharmProjects/twitter_countdown_bot/venv/lib/python3.8/site-packages/tweepy/binder.py", line 252, in _call
        return method.execute()
      File "/Users/kevin/PycharmProjects/twitter_countdown_bot/venv/lib/python3.8/site-packages/tweepy/binder.py", line 234, in execute
        raise TweepError(error_msg, resp, api_code=api_error_code)
    tweepy.error.TweepError: [{'message': 'Sorry, that page does not exist', 'code': 34}]
    
    Process finished with exit code 1

主要.py:

if __name__ == '__main__':
    authenticate = auth_twitter.authenticate()
    # Sets path to image to have the text drawn onto
    header_image = str(update_header_image.update_header())
    # Create header image and push to twitter
    authenticate.update_profile_background_image(header_image)

update_header_image.py 定义用于写入文本的基本图像

def update_header():
    image_file = create_image.createtwitterheader(headerimage=Image.open('images/TwitterHeaderImage.png'))
    return image_file

create_image.py 这是创建图像并传递优化文件的路径/名称的位置

    #  Create the header image for Twitter
def createtwitterheader(headerimage):
    # Assign header text
    headertext = "As of " + date_calc.nowdict()["day"] + ", \n" + date_calc.nowdict()["month"] + " " + \
                 date_calc.nowdict()["daydate"]
    # Snatch up the fonts
    font = ImageFont.truetype("fonts/fira-sans/FiraSans-Heavy.otf", 76)
    font2 = ImageFont.truetype("fonts/fira-sans/FiraSans-Heavy.otf", 15)
    font3 = ImageFont.truetype("fonts/fira-sans/FiraSans-Heavy.otf", 35)
    # Draw the text
    draw = ImageDraw.Draw(headerimage)
    draw.text((115, 195), emonth, (0, 0, 0), font=font)
    draw.text((229, 195), eday, (0, 0, 0), font=font)
    draw.text((106, 270), "M O N T H", (0, 0, 0), font=font2)
    draw.text((245, 270), "D A Y S", (0, 0, 0), font=font2)
    draw.text((350, 205), headertext, (255, 255, 255), font=font3)
    # Set path/filename
    filename_l = 'images/generated_images/twitter-header-' + date_calc.nowdict()["second"] + ".png"
    filename_s = 'images/generated_images/twitter-header-' + date_calc.nowdict()["second"] + "_s.png"
    # Save the image
    headerimage.save(filename_l, 'PNG')
    # Send to TinyPNG for image optimization
    source = tinify.from_file(filename_l)
    source.to_file(filename_s)
    # Show and tell (removed when in production)
    headerimage.show()
    return filename_s
4

1 回答 1

0

我调用了错误的函数。而不是 update_header_image ,我应该使用 update_profile_banner。

于 2020-09-08T17:46:41.353 回答