Interesting example of a request that works with requests but fails with httpx #3410
-
The following minimal code snippet shows a different scenario for the tiktok homepage post api, which returns validly when I use the default request with dependency
code snippetimport requests
import httpx
# This link should work for 24 hours
url = "https://www.tiktok.com/api/post/item_list/?WebIdLastTime=1732194489&aid=1988&app_language=zh-Hans&app_name=tiktok_web&browser_language=zh-CN&browser_name=Mozilla&browser_online=true&browser_platform=Win32&browser_version=5.0%20%28Windows%20NT%2010.0%3B%20Win64%3B%20x64%29%20AppleWebKit%2F537.36%20%28KHTML%2C%20like%20Gecko%29%20Chrome%2F131.0.0.0%20Safari%2F537.36&channel=tiktok_web&cookie_enabled=true&device_id=7439711114047226887&device_platform=web_pc&focus_state=true&from_page=user&history_len=4&is_fullscreen=false&is_page_visible=true&language=zh-Hans&os=windows&priority_region=&referer=®ion=SG&screen_height=1080&screen_width=1920&webcast_language=zh-Hans&tz_name=Asia%2FHong_Kong&msToken=vDHqR6aJT24paT-QKenfr-EJnH0qJxfStr_R4Fwdx_NkHt9UuDwe-g3PUkoXjUSFkQU4flCbV2QNRpvpe84eIa77OsZbKhNs9jDLinlNMK1v8LbV5JT89kYSGEhPrrSmsVGz0R3Mo36tKhTpoy52&coverFormat=2&count=5&cursor=0&secUid=MS4wLjABAAAATBiMtX2BMS2TrO3mCMYc4wWaa3iO-9lWLuUpYKC3EMjhfWWsTXj5805T-aw_EfVN&X-Bogus=DFSzswVYODUANjactKFyxM9WX7jf"
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36",
"Referer": "https://www.tiktok.com/@official_nct",
}
print("=====================================")
response = requests.get(url, headers=headers)
print(response.url)
print("Response status code:", response.status_code)
print("Response text:", response.text[:100])
print("=====================================")
response = httpx.get(url, headers=headers)
print(response.url)
print("Response status code:", response.status_code)
print("Response text:", response.text[:100])
print("=====================================") ps:If this api is not working please let me re-update the link! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
I found the problems! I cleared my dns cache and it worked, it's really quite interesting, |
Beta Was this translation helpful? Give feedback.
I found the problems! I cleared my dns cache and it worked, it's really quite interesting,
requests
don't seem to be affected by this, buthttpx
fails. I don't know if this is an accidental bug inhttpx
or not