Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/292.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 尝试使用媒体更新时出现Twython 401错误_Python_Twitter_Twython - Fatal编程技术网

Python 尝试使用媒体更新时出现Twython 401错误

Python 尝试使用媒体更新时出现Twython 401错误,python,twitter,twython,Python,Twitter,Twython,我正试图让我的raspberry pi使用特定的标签在某个用户的twitter上观看推特。当它看到符合条件的tweet时,它应该拍一张照片,然后向用户发回照片。它一直工作到应该上传图片的时候,然后我得到一个“TwitterAPI返回401(未经授权)”。我不知道为什么它会返回401,因为凭证在脚本的流式处理部分之前就起作用了。任何帮助都将不胜感激 from twython import Twython from twython import TwythonStreamer import sys

我正试图让我的raspberry pi使用特定的标签在某个用户的twitter上观看推特。当它看到符合条件的tweet时,它应该拍一张照片,然后向用户发回照片。它一直工作到应该上传图片的时候,然后我得到一个“TwitterAPI返回401(未经授权)”。我不知道为什么它会返回401,因为凭证在脚本的流式处理部分之前就起作用了。任何帮助都将不胜感激

from twython import Twython
from twython import TwythonStreamer
import sys
import os

APP_KEY = 'X'
APP_SECRET = 'X'
OAUTH_TOKEN = 'X'
OAUTH_TOKEN_SECRET = 'X'

def takePicture(id_str, screen_name):
    os.system('raspistill -o ' + str(id_str) + '_@' + str(screen_name) + '.png -t 3000 -w 1080 -h 720 -n -vf')

def photo(id_str, screen_name):
    open('/home/pi/' + str(id_str) + '_@' + str(screen_name) + '.png', 'rb')

def uppic(screen_name):
    twitter.update_status_with_media(status='@' + str(screen_name) + ' is super awesome!', media=photo)

class MyStreamer(TwythonStreamer):
    def on_success(self, data):
        print data['user']['screen_name'].encode('utf-8')
        print data['id_str'].encode('utf-8')
        print data['text'].encode('utf-8')
        takePicture(data['id_str'], data['user']['screen_name'])
        photo(data['id_str'], data['user']['screen_name'])
        uppic(data['user']['screen_name'])

    def on_error(elf, status_code, data):
        print status_code

stream = MyStreamer(APP_KEY, APP_SECRET, OAUTH_TOKEN, OAUTH_TOKEN_SECRET)
twitter = Twython(APP_KEY, APP_SECRET, OAUTH_TOKEN, OAUTH_TOKEN_SECRET)

stream.statuses.filter(track='#hashtag @user')

我创造了新的oauth秘密,解决了这个问题。但是,现在它返回:

TwythonError:Twitter API返回了403(禁止)、缺少或无效的url参数