carcabot / tiktok-signature

Generate tiktok signature token using node
733 stars 283 forks source link

trending.py returns empty response #193

Closed Roman-Kasianenko closed 11 months ago

Roman-Kasianenko commented 1 year ago

when trying to run trending.py getting empty response:

b''

and as a result error in the terminal/console:

\tiktok-signature\examples\trending.py", line 30, in <module>
    print('Cannot run node script ' + str(exit_code) + ': ' + standard_err)
TypeError: can only concatenate str (not "bytes") to str

I have tried to run it in a different way, using tiktok-signature running in docker, like this:

from pprint import pprint

import requests

referer = "https://www.tiktok.com/"
url = "https://m.tiktok.com/api/post/item_list/?aid=1988&count=30&secUid=MS4wLjABAAAAOUoQXeHglWcq4ca3MwlckxqAe-RIKQ1zlH9NkQkbLAT_h1_6SDc4zyPdAcVdTWZF&cursor=0"
headers = {
        'Content-type': 'application/json',
    }
response = requests.post('http://localhost/signature', headers=headers, data=url)

# the command was successful, handle the standard output
signature = response.json()
pprint(signature)
response = requests.get(signature['data']['signed_url'], headers={"method": "GET",
                                                                 "accept-encoding": "gzip, deflate",
                                                                 "Referer": referer,
                                                                 "user-agent": signature['data']['navigator']['user_agent'],
                                                                 "x-tt-params": signature['data']['x-tt-params']
                                                                 })

data = response.text

print('\nresult: ', data)

got the following output:

{'data': {'navigator': {'browser_language': 'en-US',
                        'browser_name': 'Mozilla',
                        'browser_platform': 'Linux x86_64',
                        'browser_version': '5.0 (Macintosh; Intel Mac OS X '
                                           '10_15_6) AppleWebKit/537.36 '
                                           '(KHTML, like Gecko) '
                                           'Chrome/98.0.4758.109 Safari/537.36',
                        'deviceScaleFactor': 1,
                        'user_agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X '
                                      '10_15_6) AppleWebKit/537.36 (KHTML, '
                                      'like Gecko) Chrome/98.0.4758.109 '
                                      'Safari/537.36'},
          'signature': '_02B4Z6wo00f01gPUPxwAAIBAOtxn34I7BZYDxDuAAOUI0c',
          'signed_url': 'https://m.tiktok.com/api/post/item_list/?aid=1988&count=30&secUid=MS4wLjABAAAAOUoQXeHglWcq4ca3MwlckxqAe-RIKQ1zlH9NkQkbLAT_h1_6SDc4zyPdAcVdTWZF&cursor=0&verifyFp=verify_5b161567bda98b6a50c0414d99909d4b&_signature=_02B4Z6wo00f01gPUPxwAAIBAOtxn34I7BZYDxDuAAOUI0c&X-Bogus=DFSzswSL8AJANVmttazlK09WcBrM',
          'verify_fp': 'verify_5b161567bda98b6a50c0414d99909d4b',
          'x-bogus': 'DFSzswSL8AJANVmttazlK09WcBrM',
          'x-tt-params': 'mb+z3Pl1d/bc+N0SKnc7nb3QUghzTPiwbDV+3XN8HaRTtr0JXAtTVnIUDTpivydJ5jkl4frk1rWltxrewy8UxPeRu9Jr7Y16B3/3NVfDAMdstYu5A/j8ty/O464zUlKXmn+QuBc3cxYCCtYyVdDL7F5WS0EN/O61UG1uxT2InAhD+0h6VWQu+Ux65eF1oDJHuVGlOw8dUtd4pXWMnW7D0mxN79BMyeyh6CNRLbo33vLbCQYJTt+TKLHmm7ZKDd6dgpgPx4O76QPV7l+6iOoWOfCS2ArHqg5jtxMJdhZ8banm4EVpd2ExL79a1R0S8JnQ'},
 'status': 'ok'}

result:  

as you can see, response from tiktok-signature and signature is generate, but if we use it in headers in doest work, the script return empty body instead of list of results.

also have tried with different urls (for example for the case/url described in https://github.com/carcabot/tiktok-signature/blob/master/examples/hashtag.js, but got the same, empty body.

To Reproduce run tranding.py from the repo or code I provided above if tiktok-signature is running in docker.

Roman-Kasianenko commented 1 year ago

it seems like msToken is required. I have tried to get it using selenium and once I have added it into headers I was able to get the data.

tonywangcn commented 1 year ago

@Roman-Kasianenko Is that possible to generate msToken with script instead of selenium?