y-young/nazurin

Twitter链接报错“Response Error: 0 Attempt to decode JSON with unexpected mimetype:”

zsbai opened this issue · 5 comments

zsbai commented

Describe the bug
尝试发送推特链接时报错

Error output / Logs

======== Running on http://0.0.0.0:7900 ========
(Press CTRL+C to quit)
2023-07-10 11:24:02,542-0400 - INFO     - nazurin.bot:167 -  - Cleaned up temporary directory
2023-07-10 11:24:05,248-0400 - INFO     - nazurin.middleware:25 - update:658614606 - Message 568: https://twitter.com/benevolels/status/1677592346597408768
2023-07-10 11:24:05,260-0400 - INFO     - nazurin.bot:123 - update:658614606 - Collection update: site=twitter, match=('1677592346597408768',)
2023-07-10 11:24:05,270-0400 - INFO     - nazurin.sites.twitter.api.web:114 - update:658614606 - Fetching tweet 1677592346597408768 from web API
2023-07-10 11:24:05,271-0400 - INFO     - nazurin.sites.twitter.api.web:178 - update:658614606 - Fetching guest token
2023-07-10 11:24:05,275-0400 - INFO     - aiohttp.web_log:206 -  - 127.0.0.1 "POST /这里是bot token HTTP/1.0" 200 152 "-" "-"
2023-07-10 11:24:05,355-0400 - INFO     - nazurin.sites.twitter.api.web:188 - update:658614606 - Fetched guest token: 1678424729982730241
Traceback (most recent call last):
  File "/root/nazurin-new/nazurin/__main__.py", line 91, in on_error
    raise exception
  File "/usr/local/lib/python3.9/dist-packages/aiogram/dispatcher/dispatcher.py", line 1394, in process_response
    response = task.result()
  File "/root/nazurin-new/nazurin/dispatcher.py", line 119, in update_collection
    await self.bot.update_collection(urls, message)
  File "/root/nazurin-new/nazurin/bot.py", line 129, in update_collection
    illust = await self.sites.handle_update(result)
  File "/root/nazurin-new/nazurin/sites/__init__.py", line 68, in handle_update
    return await handle(result["match"])
  File "/root/nazurin-new/nazurin/sites/twitter/interface.py", line 22, in handle
    illust = await Twitter().fetch(status_id)
  File "/root/nazurin-new/nazurin/sites/twitter/api/__init__.py", line 17, in fetch
    return await Twitter.web.fetch(status_id)
  File "/root/nazurin-new/nazurin/sites/twitter/api/web.py", line 84, in fetch
    tweet = await self.tweet_detail(status_id)
  File "/root/nazurin-new/nazurin/sites/twitter/api/web.py", line 123, in tweet_detail
    response = await self._request("GET", api, params=params)
  File "/usr/local/lib/python3.9/dist-packages/tenacity/_asyncio.py", line 48, in call
    do = self.iter(retry_state=retry_state)
  File "/usr/local/lib/python3.9/dist-packages/tenacity/__init__.py", line 320, in iter
    return fut.result()
  File "/usr/lib/python3.9/concurrent/futures/_base.py", line 433, in result
    return self.__get_result()
  File "/usr/lib/python3.9/concurrent/futures/_base.py", line 389, in __get_result
    raise self._exception
  File "/usr/local/lib/python3.9/dist-packages/tenacity/_asyncio.py", line 51, in call
    result = yield from fn(*args, **kwargs)
  File "/root/nazurin-new/nazurin/sites/twitter/api/web.py", line 144, in _request
    result = await response.json()
  File "/usr/local/lib/python3.9/dist-packages/aiohttp/client_reqrep.py", line 1104, in json
    raise ContentTypeError(
aiohttp.client_exceptions.ContentTypeError: 0, message='Attempt to decode JSON with unexpected mimetype: ', url=URL('https://twitter.com/i/api/graphql/1oIoGPTOJN2mSjbbXlQifA/TweetDetail?variables=%7B%22with_rux_injections%22:+false,+%22includePromotedContent%22:+false,+%22withCommunity%22:+true,+%22withQuickPromoteEligibilityTweetFields%22:+false,+%22withBirdwatchNotes%22:+false,+%22withDownvotePerspective%22:+false,+%22withReactionsMetadata%22:+false,+%22withReactionsPerspective%22:+false,+%22withVoice%22:+true,+%22withV2Timeline%22:+true,+%22focalTweetId%22:+%221677592346597408768%22%7D&features=%7B%22blue_business_profile_image_shape_enabled%22:+false,+%22responsive_web_graphql_exclude_directive_enabled%22:+true,+%22verified_phone_label_enabled%22:+false,+%22responsive_web_graphql_timeline_navigation_enabled%22:+true,+%22responsive_web_graphql_skip_user_profile_image_extensions_enabled%22:+false,+%22tweetypie_unmention_optimization_enabled%22:+true,+%22vibe_api_enabled%22:+true,+%22responsive_web_edit_tweet_api_enabled%22:+true,+%22graphql_is_translatable_rweb_tweet_is_translatable_enabled%22:+false,+%22view_counts_everywhere_api_enabled%22:+true,+%22longform_notetweets_consumption_enabled%22:+true,+%22tweet_awards_web_tipping_enabled%22:+false,+%22freedom_of_speech_not_reach_fetch_enabled%22:+false,+%22standardized_nudges_misinfo%22:+true,+%22tweet_with_visibility_results_prefer_gql_limited_actions_policy_enabled%22:+false,+%22interactive_text_enabled%22:+true,+%22responsive_web_text_conversations_enabled%22:+false,+%22longform_notetweets_richtext_consumption_enabled%22:+false,+%22responsive_web_enhance_cards_enabled%22:+false%7D')

Make sure to remove or mask all secrets, such as bot token and personal information!

Environment (please complete the following information):
Python 3.9.2
Debian系统

Additional context
看了一下,在7月7号凌晨一点还是可以正常使用的,到了7月7号十二点就报错了...试了一下浏览器无痕模式不登陆的情况下是可以正常访问推文的,应该和推特之前的措施无关

有可能是因为 Twitter 最近的限流措施,是不是短时间内浏览了大量推文?现在的限制大概是15分钟50条,这个报错之后我找时间修一下

zsbai commented

可能是被限制了,不过我这个ip倒是没有短时间浏览下载大量推特图片,7号报错后8号又尝试了另一个推文还是报错,刚才又试了几次还是不行
也可能是我这个vps的ip段被拉黑了 emmmm等您有时间了再看一下吧

zsbai commented
======== Running on http://0.0.0.0:7900 ========
(Press CTRL+C to quit)
2023-07-12 12:10:25,734-0400 - INFO     - nazurin.bot:167 -  - Cleaned up temporary directory
2023-07-12 12:10:30,145-0400 - INFO     - nazurin.middleware:25 - update:658614613 - Message 578: https://twitter.com/benevolels/status/1677592346597408768
2023-07-12 12:10:30,154-0400 - INFO     - nazurin.bot:123 - update:658614613 - Collection update: site=twitter, match=('1677592346597408768',)
2023-07-12 12:10:30,164-0400 - INFO     - nazurin.sites.twitter.api.web:114 - update:658614613 - Fetching tweet 1677592346597408768 from web API
2023-07-12 12:10:30,166-0400 - INFO     - nazurin.sites.twitter.api.web:186 - update:658614613 - Fetching guest token
2023-07-12 12:10:30,171-0400 - INFO     - aiohttp.web_log:206 -  - 127.0.0.1 "POST /这里是bot api HTTP/1.0" 200 152 "-" "-"
2023-07-12 12:10:30,247-0400 - INFO     - nazurin.sites.twitter.api.web:196 - update:658614613 - Fetched guest token: 1679161177434374148
2023-07-12 12:10:30,463-0400 - ERROR    - nazurin.sites.twitter.api.web:146 - update:658614613 - Web API Error: 404, 
图片 >_(
======== Running on http://0.0.0.0:7900 ========
(Press CTRL+C to quit)
2023-07-12 12:10:25,734-0400 - INFO     - nazurin.bot:167 -  - Cleaned up temporary directory
2023-07-12 12:10:30,145-0400 - INFO     - nazurin.middleware:25 - update:658614613 - Message 578: https://twitter.com/benevolels/status/1677592346597408768
2023-07-12 12:10:30,154-0400 - INFO     - nazurin.bot:123 - update:658614613 - Collection update: site=twitter, match=('1677592346597408768',)
2023-07-12 12:10:30,164-0400 - INFO     - nazurin.sites.twitter.api.web:114 - update:658614613 - Fetching tweet 1677592346597408768 from web API
2023-07-12 12:10:30,166-0400 - INFO     - nazurin.sites.twitter.api.web:186 - update:658614613 - Fetching guest token
2023-07-12 12:10:30,171-0400 - INFO     - aiohttp.web_log:206 -  - 127.0.0.1 "POST /这里是bot api HTTP/1.0" 200 152 "-" "-"
2023-07-12 12:10:30,247-0400 - INFO     - nazurin.sites.twitter.api.web:196 - update:658614613 - Fetched guest token: 1679161177434374148
2023-07-12 12:10:30,463-0400 - ERROR    - nazurin.sites.twitter.api.web:146 - update:658614613 - Web API Error: 404, 

我这边没这个问题……试试重启之类的吧,如果有需要可以另开 Issue

zsbai commented

奇怪的说 已经更新到最新的commit并重启了,我再试试看是不是ip的问题