0

Windows 11:

  • Host OS
  • Version 22H2 (OS Build 22621.1702)
  • Python 3.11.2
  • requests 2.30.0

Ubuntu 22.04:

  • Running under VMware® Workstation 16 Pro 16.2.5 build-20904516
  • Ubuntu 22.04.2 LTS
  • Python 3.10.6
  • requests 2.30.0
  • Network card is Bridge
import requests

session = requests.Session()
session.headers = {
    "User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36"
}

session.cookies.set("auth_token", "a81ce3a06e7134d6d74631b91e790506f1825a93", domain=".twitter.com", path="/")
session.cookies.set("ct0", "b43a6f372b62dfa33b58f95c08ee72ab7e5ee6809f94cd0de35512d89b56788aa56fff65f0d8041d84eb84de2bd59642c0dec8143ed3836ffe88fc71004b440c424750a696ec309da81a13a74c4b2313", domain=".twitter.com", path="/")

url = "https://twitter.com/i/api/2/search/adaptive.json"

headers = {
    "authority": "twitter.com",
    "method": "GET",
    "scheme": "https",
    "accept": "*/*",
    "accept-language": "en-US,en;q=0.9",
    "authorization": "Bearer AAAAAAAAAAAAAAAAAAAAANRILgAAAAAAnNwIzUejRCOuH5E6I8xnZz4puTs%3D1Zv7ttfk8LF81IUq16cHjhLTvJu4FA33AGWWjCpTnA",
    "referer": "https://twitter.com/",
    "sec-ch-ua": '"Google Chrome";v="113", "Chromium";v="113", "Not-A.Brand";v="24"',
    "sec-ch-ua-mobile": "?0",
    "sec-ch-ua-platform": '"Linux"',
    "sec-fetch-dest": "empty",
    "sec-fetch-mode": "cors",
    "sec-fetch-site": "same-origin",
    "x-csrf-token": "b43a6f372b62dfa33b58f95c08ee72ab7e5ee6809f94cd0de35512d89b56788aa56fff65f0d8041d84eb84de2bd59642c0dec8143ed3836ffe88fc71004b440c424750a696ec309da81a13a74c4b2313",
    "x-twitter-active-user": "yes",
    "x-twitter-auth-type": "OAuth2Session",
    "x-twitter-client-language": "en"
}

params = {
    "include_profile_interstitial_type": 1,
    "include_blocking": 1,
    "include_blocked_by": 1,
    "include_followed_by": 1,
    "include_want_retweets": 1,
    "include_mute_edge": 1,
    "include_can_dm": 1,
    "include_can_media_tag": 1,
    "include_ext_has_nft_avatar": 1,
    "include_ext_is_blue_verified": 1,
    "include_ext_verified_type": 1,
    "include_ext_profile_image_shape": 1,
    "skip_status": 1,
    "cards_platform": "Web-12",
    "include_cards": 1,
    "include_ext_alt_text": True,
    "include_ext_limited_action_results": False,
    "include_quote_count": True,
    "include_reply_count": 1,
    "tweet_mode": "extended",
    "include_ext_views": True,
    "include_entities": True,
    "include_user_entities": True,
    "include_ext_media_color": True,
    "include_ext_media_availability": True,
    "include_ext_sensitive_media_warning": True,
    "include_ext_trusted_friends_metadata": True,
    "send_error_codes": True,
    "simple_quoted_tweet": True,
    "q": "(@tiptest238058) until:2023-05-17 since:2023-05-16",
    "query_source": "typed_query",
    "count": 20,
    "requestContext": "launch",
    "pc": 1,
    "spelling_corrections": 1,
    "include_ext_edit_control": True,
    "ext": "mediaStats,highlightedLabel,hasNftAvatar,voiceInfo,birdwatchPivot,enrichments,superFollowMetadata,unmentionInfo,editControl,vibe"
}

response = session.get(url, headers=headers, params=params)
print(response.content)

I get Response 200 and a JSON file on Windows but Response 404 on Ubuntu. I have tried to upgrade python to 3.11 on Ubuntu but still not working, clean install of Ubuntu so I'm back to Python 3.10.6. Access to internet checked, I get responses for other links, firewall Allow All. Auth and ct0 tokens are from a dummy account so feel free to use them or replace with your own.

mkrieger1
  • 19,194
  • 5
  • 54
  • 65
  • My guess is that your CSRF token is invalid. See: https://stackoverflow.com/questions/34782493/difference-between-csrf-and-x-csrf-token – DarkKnight May 18 '23 at 09:47
  • @DarkKnight I don't think that is the problem. The same script works when run from windows and I get 404 - not found, not 403 - Forbidden as I get if I play too much with the parameters – Flo Rentin May 18 '23 at 13:53
  • Also, from your link X-CSRF uses a link between cookie and token and they match in my case – Flo Rentin May 18 '23 at 13:59

0 Answers0