从url更改twitter横幅

2024-10-01 15:44:08 发布

您现在位置:Python中文网/ 问答频道 /正文

我如何使用tweepy library:https://github.com/tweepy/tweepy/blob/v2.3.0/tweepy/api.py#L392使用url中的图像更改twitter横幅

到目前为止,我得到了这个结果:

def banner(self):
    url = 'https://blog.snappa.com/wp-content/uploads/2019/01/Twitter-Header-Size.png'
    file = requests.get(url)
    self.api.update_profile_banner(filename=file.content)

ValueError: stat: embedded null character in path

似乎文件名要求下载图像。是否要在不下载图像然后将其删除的情况下处理此问题


Tags: pyhttps图像selfgithubcomapiurl
2条回答

查看库的代码,您可以做您想要的事情

def update_profile_banner(self, filename, *args, **kargs):
    f = kargs.pop('file', None)

因此,您需要做的是提供文件名和文件名:

filename = url.split('/')[-1]
self.api.update_profile_banner(filename, file=file.content)
import tempfile

def banner():
    url = 'file_url'
    file = requests.get(url)
    temp = tempfile.NamedTemporaryFile(suffix=".png")
    try:
        temp.write(file.content)         
        self.api.update_profile_banner(filename=temp.name)
    finally:
        temp.close()

相关问题 更多 >

    热门问题