Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[QUESTION]403错误更新device_id和cookie后,修改f2/apps/tiktok/utils.py:60以验证,返回device_id为空,并且获取仍然失败 #199

Open
2 tasks
xiaolinli123 opened this issue Nov 14, 2024 · 4 comments
Labels
等待反馈(feedback) 需要补充信息或配合测试(Feedbackers are required to add information or cooperate with the test)

Comments

@xiaolinli123
Copy link

  • 在提问时请注意不要包含个人敏感信息
  • 我明白我的提问可能不会得到明确回复或解决。

问题描述
403错误更新device_id和cookie后,修改f2/apps/tiktok/utils.py:60以验证,返回device_id为空,并且获取仍然失败

其他细节

@classmethod
    def brm_device(cls) -> dict:
        print('HEYYYY', cls.base_request_model().get("device", {}))
        return cls.base_request_model().get("device", {})

截图/代码示例

C:\Users\Administrator>f2 tk -c tk.yaml
WARNING  您当前使用的版本 0.0.1.6 可能已过时,请考虑及时升级到最新版本 0.0.1.6,请使用 pip install -U f2 更新
INFO     应用:tiktok
INFO     模式:post
INFO     主配置路径:C:\Users\Administrator\AppData\Local\Programs\Python\Python312\Lib\site-packages\f2\conf\app.yaml
INFO     自定义配置路径:C:\Users\Administrator\tk.yaml
HEYYYY {}
HEYYYY {}
ERROR    Traceback (most recent call last):
           File "C:\Users\Administrator\AppData\Local\Programs\Python\Python312\Lib\site-packages\f2\utils\_dl.py", line 42, in
         get_content_length
             response.raise_for_status()
           File "C:\Users\Administrator\AppData\Local\Programs\Python\Python312\Lib\site-packages\httpx\_models.py", line 761, in
         raise_for_status
             raise HTTPStatusError(message, request=request, response=self)
         httpx.HTTPStatusError: Client error '403 Forbidden' for url
         'https://v16-webapp-prime.tiktok.com/video/tos/alisg/tos-alisg-pve-0037c001/oQNEglFrjQDei4iAqC7gf7EkmZIXR9FBQivLdB/?a=19
         88&bti=ODszNWYuMDE6&ch=0&cr=3&dr=0&lr=all&cd=0%7C0%7C0%7C&cv=1&br=7050&bt=3525&cs=0&ds=3&ft=4fUEKMwF8Zmo0t3chb4jVUHkrpWr
         Ksd.&mime_type=video_mp4&qs=0&rc=ODxmZjtmPDo8OGU4OjRmZ0BpamtlOnY5cjtldDMzODczNEA1X15gYDAyNl4xLzMwLWMtYSNkLWA2MmRraWpgLS1
         kMS1zcw%3D%3D&btag=e00098000&expire=1731592792&l=20241114075642E0497BD3DB575609CF43&ply_type=2&policy=2&signature=7b82c7
         06d16705a28d6ab0557f47b91d&tk=tt_chain_token'
         For more information check: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/403

         During handling of the above exception, another exception occurred:

         Traceback (most recent call last):
           File "C:\Users\Administrator\AppData\Local\Programs\Python\Python312\Lib\site-packages\f2\utils\_dl.py", line 73, in
         get_content_length
             response.raise_for_status()
           File "C:\Users\Administrator\AppData\Local\Programs\Python\Python312\Lib\site-packages\httpx\_models.py", line 761, in
         raise_for_status
             raise HTTPStatusError(message, request=request, response=self)
         httpx.HTTPStatusError: Client error '403 Forbidden' for url
         'https://v16-webapp-prime.tiktok.com/video/tos/alisg/tos-alisg-pve-0037c001/oQNEglFrjQDei4iAqC7gf7EkmZIXR9FBQivLdB/?a=19
         88&bti=ODszNWYuMDE6&ch=0&cr=3&dr=0&lr=all&cd=0%7C0%7C0%7C&cv=1&br=7050&bt=3525&cs=0&ds=3&ft=4fUEKMwF8Zmo0t3chb4jVUHkrpWr
         Ksd.&mime_type=video_mp4&qs=0&rc=ODxmZjtmPDo8OGU4OjRmZ0BpamtlOnY5cjtldDMzODczNEA1X15gYDAyNl4xLzMwLWMtYSNkLWA2MmRraWpgLS1
         kMS1zcw%3D%3D&btag=e00098000&expire=1731592792&l=20241114075642E0497BD3DB575609CF43&ply_type=2&policy=2&signature=7b82c7
         06d16705a28d6ab0557f47b91d&tk=tt_chain_token'
         For more information check: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/403

ERROR    HTTP状态错误, 尝试GET请求失败:
         https://v16-webapp-prime.tiktok.com/video/tos/alisg/tos-alisg-pve-0037c001/oQNEglFrjQDei4iAqC7gf7EkmZIXR9FBQivLdB/?a=198
         8&bti=ODszNWYuMDE6&ch=0&cr=3&dr=0&lr=all&cd=0%7C0%7C0%7C&cv=1&br=7050&bt=3525&cs=0&ds=3&ft=4fUEKMwF8Zmo0t3chb4jVUHkrpWrK
         sd.&mime_type=video_mp4&qs=0&rc=ODxmZjtmPDo8OGU4OjRmZ0BpamtlOnY5cjtldDMzODczNEA1X15gYDAyNl4xLzMwLWMtYSNkLWA2MmRraWpgLS1k
         MS1zcw%3D%3D&btag=e00098000&expire=1731592792&l=20241114075642E0497BD3DB575609CF43&ply_type=2&policy=2&signature=7b82c70
         6d16705a28d6ab0557f47b91d&tk=tt_chain_token, 错误详情: Client error '403 Forbidden' for url
         'https://v16-webapp-prime.tiktok.com/video/tos/alisg/tos-alisg-pve-0037c001/oQNEglFrjQDei4iAqC7gf7EkmZIXR9FBQivLdB/?a=19
         88&bti=ODszNWYuMDE6&ch=0&cr=3&dr=0&lr=all&cd=0%7C0%7C0%7C&cv=1&br=7050&bt=3525&cs=0&ds=3&ft=4fUEKMwF8Zmo0t3chb4jVUHkrpWr
         Ksd.&mime_type=video_mp4&qs=0&rc=ODxmZjtmPDo8OGU4OjRmZ0BpamtlOnY5cjtldDMzODczNEA1X15gYDAyNl4xLzMwLWMtYSNkLWA2MmRraWpgLS1
         kMS1zcw%3D%3D&btag=e00098000&expire=1731592792&l=20241114075642E0497BD3DB575609CF43&ply_type=2&policy=2&signature=7b82c7
         06d16705a28d6ab0557f47b91d&tk=tt_chain_token'
         For more information check: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/403
WARNING  链接
         https://v16-webapp-prime.tiktok.com/video/tos/alisg/tos-alisg-pve-0037c001/oQNEglFrjQDei4iAqC7gf7EkmZIXR9FBQivLdB/?a=198
         8&bti=ODszNWYuMDE6&ch=0&cr=3&dr=0&lr=all&cd=0%7C0%7C0%7C&cv=1&br=7050&bt=3525&cs=0&ds=3&ft=4fUEKMwF8Zmo0t3chb4jVUHkrpWrK
         sd.&mime_type=video_mp4&qs=0&rc=ODxmZjtmPDo8OGU4OjRmZ0BpamtlOnY5cjtldDMzODczNEA1X15gYDAyNl4xLzMwLWMtYSNkLWA2MmRraWpgLS1k
         MS1zcw%3D%3D&btag=e00098000&expire=1731592792&l=20241114075642E0497BD3DB575609CF43&ply_type=2&policy=2&signature=7b82c70
         6d16705a28d6ab0557f47b91d&tk=tt_chain_token 内容长度为0,尝试下一个链接是否可用
WARNING  所有链接都无法下载
ERROR    Traceback (most recent call last):
           File "C:\Users\Administrator\AppData\Local\Programs\Python\Python312\Lib\site-packages\f2\utils\_dl.py", line 42, in
         get_content_length
             response.raise_for_status()
           File "C:\Users\Administrator\AppData\Local\Programs\Python\Python312\Lib\site-packages\httpx\_models.py", line 761, in
         raise_for_status
             raise HTTPStatusError(message, request=request, response=self)
         httpx.HTTPStatusError: Client error '403 Forbidden' for url
         'https://v16-webapp-prime.tiktok.com/video/tos/alisg/tos-alisg-pve-0037c001/oQFhmBE3WRDogMACI52EBT2yfQFlRsbENRLBfE/?a=19
         88&bti=ODszNWYuMDE6&ch=0&cr=3&dr=0&lr=all&cd=0%7C0%7C0%7C&cv=1&br=6490&bt=3245&cs=0&ds=3&ft=4fUEKMwF8Zmo0t3chb4jVUHkrpWr
         Ksd.&mime_type=video_mp4&qs=0&rc=N2dkaTw0Njw5NzU8NjNkPEBpamdzaHU5cjM0dDMzODczNEBiM2AxYC9eNS4xNC41MjMwYSNzNWxkMmRrX21gLS1
         kMS1zcw%3D%3D&btag=e00098000&expire=1731592807&l=20241114075642E0497BD3DB575609CF43&ply_type=2&policy=2&signature=607822
         ceaf899765a8907ee01b929cc9&tk=tt_chain_token'
         For more information check: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/403

         During handling of the above exception, another exception occurred:

         Traceback (most recent call last):
           File "C:\Users\Administrator\AppData\Local\Programs\Python\Python312\Lib\site-packages\f2\utils\_dl.py", line 73, in
         get_content_length
             response.raise_for_status()
           File "C:\Users\Administrator\AppData\Local\Programs\Python\Python312\Lib\site-packages\httpx\_models.py", line 761, in
         raise_for_status
             raise HTTPStatusError(message, request=request, response=self)
         httpx.HTTPStatusError: Client error '403 Forbidden' for url
         'https://v16-webapp-prime.tiktok.com/video/tos/alisg/tos-alisg-pve-0037c001/oQFhmBE3WRDogMACI52EBT2yfQFlRsbENRLBfE/?a=19
         88&bti=ODszNWYuMDE6&ch=0&cr=3&dr=0&lr=all&cd=0%7C0%7C0%7C&cv=1&br=6490&bt=3245&cs=0&ds=3&ft=4fUEKMwF8Zmo0t3chb4jVUHkrpWr
         Ksd.&mime_type=video_mp4&qs=0&rc=N2dkaTw0Njw5NzU8NjNkPEBpamdzaHU5cjM0dDMzODczNEBiM2AxYC9eNS4xNC41MjMwYSNzNWxkMmRrX21gLS1
         kMS1zcw%3D%3D&btag=e00098000&expire=1731592807&l=20241114075642E0497BD3DB575609CF43&ply_type=2&policy=2&signature=607822
         ceaf899765a8907ee01b929cc9&tk=tt_chain_token'
         For more information check: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/403

image

期望的支持
获取device_id为空是否为导致获取失败的原因?为什么device_id获取为空?

配置文件详情

1. conf.yaml

f2:
  version: "0.0.1.6"

  tiktok:

    BaseRequestModel:
      browser:
        language: zh-CN
        name: Mozilla
        platform: Win32
        version: 5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36

      device:
        id: "7435947509317944864"
        platform: web_pc

      os: windows
      region: SG
      priority_region: ""
      webcast_language: zh-Hans
      tz_name: Asia/Hong_Kong

    headers:
      User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36
      Referer: https://www.tiktok.com/

    proxies:
      http://:
      https://:
    
    msToken:
      url: https://mssdk-sg.tiktok.com/web/common?msToken=QnC7zMMh1cpaDTxHDHnabNOrqaWv49JwA1IAq3AIFvrdaqQi8Rs_YlXSya1vN-4b6C1MgpWpS2cL1oakaUEDe3pUDMLpCbdSc3b3V98Fux0AuwXn_9Ns3FyMTnFRmSOOOVeGg6bVXMSGoMG6dq3k
      url2: https://mssdk-sg.tiktok.com/web/report?msToken=QnC7zMMh1cpaDTxHDHnabNOrqaWv49JwA1IAq3AIFvrdaqQi8Rs_YlXSya1vN-4b6C1MgpWpS2cL1oakaUEDe3pUDMLpCbdSc3b3V98Fux0AuwXn_9Ns3FyMTnFRmSOOOVeGg6bVXMSGoMG6dq3k
      magic: 538969122
      version: 1
      dataType: 8
      strData: 3g+ZrAO5JQgfqCRzb689RAbiueodAexjAjn2plyPVBdOArbRM66UOTnZPoVTDDw8GZ8TL/CO13bWedlvWSA8kCODHA6mjO1Af5hgak+1NHbb8EvfuahWFDL8x8hruWn4t6qb79DhOy64REx1nsO6ub4SX4cKdgs+ZXTjUItB2WKddXo7CKikuywT8SJ0TcwZ+z/9hSsawqJXawopS5H8bOF0o3qPn+CwkoWkXBUu4iwkI5UzL9/k18Gwq1BxAiCbyl2kCHJaox7md1H+KfQ0lU9fBhfVBuXa3jNkT5GfyASaBNeJXdhHwuPfEGI6a+4FOaO0MEGzOWDzhu6joo89ooEPo1XV+UJE2KLC5tStxSBibUvn+wZSfGmcpPfYl0jB0H2vLqyaveYraOx8WRE/G/Y9DkbBLJvz7E8sDZ/v1fCUVs1JDDewE/yn2aqOHr3NxUjOnylKl5WWSCPeSR4ZTXRR1ZJhvpGKP7XYc3tkOjBSQ70cXnl53dAQ6aouUVMcztSlkXh4goI46tgJDjTiJJILHBr03dM/1KwVzqoEEO8f7JBhfQo4OR6Y48PXomshJmZhDiEmtkqLndpZY2I/B8q0EShuPlDCFRW7iob6kFahyqDfpOmK15kzCX2n7eu7zqDGgpJuHEtULF9803lR5QBt104ET49RbnDJ+ipbz1bFvS2FJQ2rfktNlwjqdBT8UzfFPHyZk6z4cSxYIfPRj1lB8fDwTwv3PUSRxUZSwkuGoZbc6j/6hxwZaY0xxIEbb9DlOmQZY4qyiqSziZ8HGWsQ9uD95dO4lX6GlZaeh7mKsjLSKSdUt13YeGAciqjTvSPyO/pZ5xc3+i+5hY4A290/JiTmIyFBOrRrlmIhPEQe9OEJn0DPXYgliYUO1nljEi6q/4HMFdXFmlw6nC8/kL9EeinisX7g6PbdHuRcKONXZpXxBevL8xD5Z8SvFKH/uQmYHrJlybiKHjDIMq7vc59NBw2VDQBmRqa8NTh2XLwIryjoBIHuNSBngSZwJE==

    ttwid:
      url: https://www.tiktok.com/ttwid/check/
      data: '{"aid":1988,"service":"www.tiktok.com","union":false,"unionHost":"","needFid":false,"fid":"","migrate_priority":0}'
      cookie: ttwid=1%7C3uOVjidbOFBmdS6Aci5oeBb8Ta-HWpeyp2dvhl2Ib2E%7C1716637053%7C462867ee452aecd60a854225b854ff4498e9b99c13d4826a3e2a4e58a4c55134;

    odin_tt:
      url: https://www.tiktok.com/passport/web/account/info/?WebIdLastTime=1716637053&aid=1459&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%2F124.0.0.0%20Safari%2F537.36&channel=tiktok_web&cookie_enabled=true&device_id=7372899909097571857&device_platform=web_pc&focus_state=true&from_page=fyp&history_len=2&is_fullscreen=false&is_page_visible=true&odinId=7372898697492972561&os=windows&priority_region=&referer=&region=SG&screen_height=1080&screen_width=1920&tz_name=Asia%2FHong_Kong&webcast_language=zh-Hans

2. app.yaml

app.yaml是系统原有的,只在f2 tk --auto-cookie firefox时自动修改了其中的cookie

3. tk.yaml

tiktok:
  url: https://www.tiktok.com/@sjjw_siz
  music: null
  cover: null
  desc: null
  path: download
  folderize: null
  mode: post
  naming: null
  cookie: null
  keyword: null
  interval: all
  timeout: null
  max_connections: null
  max_counts: null
  max_retries: null
  max_tasks: null
  page_counts: null
  languages: null




@xiaolinli123 xiaolinli123 added the 提问(question) 想得到更多的详细支持(Further information is requested) label Nov 14, 2024
@Johnserf-Seed
Copy link
Owner

如果不是comf.yaml修改device_id后没保存是不会获取不到的

@Johnserf-Seed Johnserf-Seed added 等待反馈(feedback) 需要补充信息或配合测试(Feedbackers are required to add information or cooperate with the test) and removed 提问(question) 想得到更多的详细支持(Further information is requested) labels Nov 21, 2024
@xiaolinli123
Copy link
Author

保存了

@skyhhuc
Copy link

skyhhuc commented Nov 24, 2024

还有就是我获取到了deviceId,他有两个deviceId的值,以哪个为主啊?另外那个QA讲的好不详细,这个device id是conf.yaml里面的device下面的id的值是吧?我替换了,那后面的cookie所谓的增量替换是哪里替换?是app.yaml里面我从浏览器获取的cookie值里面去替换对应字段的值吗?还是怎么弄?我替换之后直接是响应为空,如果只改了device id,还是提示403 forbidden。
888888

@Johnserf-Seed
Copy link
Owner

还有就是我获取到了deviceId,他有两个deviceId的值,以哪个为主啊?另外那个QA讲的好不详细,这个device id是conf.yaml里面的device下面的id的值是吧?我替换了,那后面的cookie所谓的增量替换是哪里替换?是app.yaml里面我从浏览器获取的cookie值里面去替换对应字段的值吗?还是怎么弄?我替换之后直接是响应为空,如果只改了device id,还是提示403 forbidden。 888888

  1. 有多个设备id是因为代码片段里提供了完整ck的选项,两者选任一即可
  2. 增量替换的意思是避免有人直接把代码片段的ck粘入,只需将对应值替换即可
  3. 响应空而非403说明设备id与cookie的绑定是对的,是你需要更换一个高质量的代理,httpx这个库最近会频繁空响应的原因与dns有关

测试一切正常
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
等待反馈(feedback) 需要补充信息或配合测试(Feedbackers are required to add information or cooperate with the test)
Projects
None yet
Development

No branches or pull requests

3 participants