简体   繁体   中英

a request not working with python requests

so i have a slight problem with a request, i have this url:

https://m.tiktok.com/node/share/user/@{username}?aid=1988

well basically this url returns account's info, as name and whatsoever, it seem to work if you request it with a browser, it's ok, it will work, also works with curl , but when i try to request it with Python requests it just returns false response:

{statusCode: 0,body: {userData: {},statusCode: -1,shareUser: {}}} 

i tried to use allow_redirect=False but it didn't really seem to work, my code:

heads={"user-agent":"Mozilla/5.0 (Linux; Android 11; SM-A217F) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Mobile Safari/537.36"}
handler=requests.get("https://m.tiktok.com/node/share/user/@someuser",headers=heads,allow_redirects=False)
print(handler.text)

Just read the documentation here..

Its important and required to use headers and so on..

Try this code, might work!

import requests
headers = {
    "Accept": "application/json",
    "Content-Type": "application/json"
}

data = {
        "access_token": access_token,
        "open_id": open_id,
        "fields": [
            "open_id",
            "union_id",
            "avatar_url",
            "avatar_url_100",
            "avatar_url_200",
            "avatar_large_url",
            "display_name"
        ]
    }

user_info = requests.post(f"https://m.tiktok.com/node/share/user/@{user}", data=None, json=None, **kwargs)

print(user_info.json())

And please read the documentation!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM