Why does my Twitter stream give me the HTTP Error: 406?
Why does my Twitter stream give me the HTTP Error: 406?
这是我的代码。一切正常,但是当 Twitter Stream 应该开始时出现以下错误:Stream encountered HTTP Error: 406
对于普通流,它运行良好,但对于异步流,它却不行。我的错误在哪里?
import discord
import tweepy
import tweepy.asynchronous
class Stream(tweepy.asynchronous.AsyncStream):
async def on_connect(self):
print("connected")
async def on_status(self, status):
print(status.text)
async def on_exception(self, exception):
print(exception)
print("!exception")
"""async def on_request_error(self, status_code):
print(status_code)"""
#If An error occurs then the programm should be restartet
"""await restart(discord_client=client, twitter_stream = self)"""
async def on_closed(self, resp):
print(resp)
class Client(discord.Client):
async def on_ready(self):
#creating stream
stream = Stream(keys + tokens)
#creating api
auth = tweepy.OAuthHandler(keys)
auth.set_access_token(tokens)
api = tweepy.API(auth)
#getting specific users which the stream should follow
follow_list = [screen_name]
follower_ids = []
for _ in follow_list:
follow = int(api.get_user(screen_name = _).id)
print(follow)
follower_ids.append(follow)
print(str(follower_ids))
#starting Stream
stream.filter(follow = follow_list)
print("start")
client = Client()
client.run(token)
这可能是因为您为 AsyncStream.filter
的 follow
参数传递了无效 ID。
follow_list
似乎是一个列表,其中包含单个屏幕名称或屏幕名称列表,而不是用户 ID 列表。看来您可能打算改用 follower_ids
。
406 不可接受的 HTTP 错误表示:
At least one request parameter is invalid. For example, the filter endpoint returns this status if:
- The track keyword is too long or too short.
- An invalid bounding box is specified.
- Neither the track nor follow parameter are specified.
- The follow user ID is not valid.
https://developer.twitter.com/en/docs/twitter-api/v1/tweets/filter-realtime/guides/connecting
这是我的代码。一切正常,但是当 Twitter Stream 应该开始时出现以下错误:Stream encountered HTTP Error: 406
对于普通流,它运行良好,但对于异步流,它却不行。我的错误在哪里?
import discord
import tweepy
import tweepy.asynchronous
class Stream(tweepy.asynchronous.AsyncStream):
async def on_connect(self):
print("connected")
async def on_status(self, status):
print(status.text)
async def on_exception(self, exception):
print(exception)
print("!exception")
"""async def on_request_error(self, status_code):
print(status_code)"""
#If An error occurs then the programm should be restartet
"""await restart(discord_client=client, twitter_stream = self)"""
async def on_closed(self, resp):
print(resp)
class Client(discord.Client):
async def on_ready(self):
#creating stream
stream = Stream(keys + tokens)
#creating api
auth = tweepy.OAuthHandler(keys)
auth.set_access_token(tokens)
api = tweepy.API(auth)
#getting specific users which the stream should follow
follow_list = [screen_name]
follower_ids = []
for _ in follow_list:
follow = int(api.get_user(screen_name = _).id)
print(follow)
follower_ids.append(follow)
print(str(follower_ids))
#starting Stream
stream.filter(follow = follow_list)
print("start")
client = Client()
client.run(token)
这可能是因为您为 AsyncStream.filter
的 follow
参数传递了无效 ID。
follow_list
似乎是一个列表,其中包含单个屏幕名称或屏幕名称列表,而不是用户 ID 列表。看来您可能打算改用 follower_ids
。
406 不可接受的 HTTP 错误表示:
At least one request parameter is invalid. For example, the filter endpoint returns this status if:
- The track keyword is too long or too short.
- An invalid bounding box is specified.
- Neither the track nor follow parameter are specified.
- The follow user ID is not valid.
https://developer.twitter.com/en/docs/twitter-api/v1/tweets/filter-realtime/guides/connecting