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

终于解决啦!!!Util\XB.py", line 50, in getXbogus UnboundLocalError: local variable 'response' referenced before assignment #361

Open
WWRichard opened this issue Mar 21, 2023 · 10 comments
Assignees
Labels
故障(bug) 代码问题导致的错误(Bugs caused by code problems) 额外求助(help wanted) 非项目代码错误的求助(Extra attention is needed) 无效(invalid) 非代码故障导致错误或异常(Non-code faults causing errors or anomalies)

Comments

@WWRichard
Copy link

WWRichard commented Mar 21, 2023

``描述出现的错误
对bug的清晰而简洁的描述。
运行代码下载视频时出现如下错误
[ 错误 ]:Expecting value: line 1 column 1 (char 0)
Traceback (most recent call last):
File "D:\Tiktok\TikTokDownload-main\example.py", line 19, in
TK.video_download(line, "no", downloadFold + '/' + nowTime)
File "D:\Tiktok\TikTokDownload-main\TikTokDownload.py", line 142, in video_download
jx_url = Util.Urls().POST_DETAIL + Util.XBogus(
File "D:\Tiktok\TikTokDownload-main\Util\XB.py", line 31, in init
self.getXbogus(url)
File "D:\Tiktok\TikTokDownload-main\Util\XB.py", line 50, in getXbogus
self.params = response["result"][0]["paramsencode"]
UnboundLocalError: local variable 'response' referenced before assignment
bug复现
复现这次行为的步骤:
1.更改了什么什么
2.点击了什么什么
3.“……”

截图
如果适用,添加屏幕截图以帮助解释您的问题。
230321_22-28-30

桌面(请填写以下信息):
-操作系统:[例如windows10 64bit]
-vpn代理[例如开启、关闭]
-版本[如1.2.3]

附文
=====================问题解决了!!!!!!!!
首先,之前使用不运行最外层那个 server.bat 是可以正常下载的,后来不知道哪天,就不行了,然后就需要输入Cookies,再后来又不行了, 出现in getXbogus UnboundLocalError: local variable 'response' referenced before assignment这个错误
解决完整的解决步骤如下。
重新下载了完整的项目原码
cd TikTokDownload-main #进源码目录
python -m venv env #创建虚拟环境,不然安装依赖容易因为版本冲突出错
.\env\Scripts\activate #进入虚拟环境
pip install -r requirements.txt #安装依赖,安装node软件就自已百度了,我之前装过
cd Util #进入Util目录
npm i #安装node依赖
cd .. #退回上层目录
.\server.bat #运行服务
230331_15-05-07
服务运行成功的效果
230331_15-11-06
打开conf.ini, 设置cookie
230331_15-14-10
重新打开一个终端
.\env\Scripts\activate #进入虚拟环境
python .\TikTokDownload.py -u "你要下载的视频链接"
就可以正常下载啦
有问题可以问我
230331_15-23-28
230331_15-36-18
230331_18-04-36

def download(video_url, music_url, video_title, music_title, headers, music, name):
    # 视频下载
    if video_url == '':
        print('[  提示  ]:该视频可能无法下载哦~\r')
        return
    else:
        r = requests.get(url=video_url, headers=headers)
        if not Util.Status_Code(r.status_code):
            if video_title == '':
                video_title = '[  提示  ]:此视频没有文案_%s\r' % music_title
            video_title = Util.replaceT(video_title)
            music_title = Util.replaceT(music_title)
            if name == "":
                name = video_title
            else:
                if not os.path.exists(name):
                    os.makedirs(name)
                name += '/' + video_title
            with open(f'{name}.mp4', 'wb') as f:
                f.write(r.content)
                print('[  视频  ]:%s.mp4 下载完成\r' % name)

    if music_url == '':
        print('[  提示  ]:下载出错\r')
        # return
    else:
        # 原声下载
        if music != 'yes':
            print('[  提示  ]:不下载%s视频原声\r' % video_title)
            # return
        else:
            r = requests.get(url=music_url, headers=headers)
            with open(f'{music_title}.mp3', 'wb') as f:
                f.write(r.content)
                print('[  音频  ]:%s.mp3 下载完成\r' % music_title)
            # return
import TikTokDownload as TK
import os
import time
import Util
# 单视频下载
# TK.video_download(*TK.main())
urlsFileName = 'DouYingDownloadUrls.txt'
downloadFold = 'Download'
if not os.path.exists(urlsFileName):
    print('请将需要下载的抖音链接放在 ' + urlsFileName + ' 文件中,每行一个链接')
else:
    if not os.path.exists(downloadFold):
        os.mkdir(downloadFold)
    nowTime = time.strftime("%Y%m%d%H")
    with open(urlsFileName, encoding='utf-8') as fh:
        txt = fh.read().split('\n')
    cmd = Util.Command()
    headers = Util.Cookies(cmd.setting()).dyheaders
    for line in txt:
        if line.strip() == "":
            continue
        TK.video_download(line, "no", downloadFold + '/' + nowTime, headers)

call .\env\Scripts\activate
python example.py
pause

@WWRichard WWRichard added 故障(bug) 代码问题导致的错误(Bugs caused by code problems) 额外求助(help wanted) 非项目代码错误的求助(Extra attention is needed) 无效(invalid) 非代码故障导致错误或异常(Non-code faults causing errors or anomalies) labels Mar 21, 2023
@WWRichard WWRichard changed the title [BUG] Util\XB.py", line 50, in getXbogus UnboundLocalError: local variable 'response' referenced before assignment Mar 21, 2023
@eightrivers
Copy link

出现同样的错误:HTTPConnectionPool(host='47.115.200.238', port=80): Max retries exceeded with url: /xg/path?url=sec_user_id=MS4wLjABAAAA8AIINGj240azZm5XhR7kiIcGh--VxzHoskD7gkzyw7Q%26count=35%26max_cursor=0%26aid=1128%26version_name=23.5.0%26device_platform=android%26os_version=2333 (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x000001AF59148FD0>: Failed to establish a new connection: [WinError 10061] 由于目标计算机积极拒绝,无法连接。'))

Win 11 中文 x64最新版,每次都会复现。

跪请大神出手!

@zfanxingzz
Copy link

频繁请求后,出现了的同样的问题

@WWRichard
Copy link
Author

有人传说是IP被封,可是我用手机共享的热点也是报这个错呀

@dd-hf
Copy link

dd-hf commented Mar 22, 2023

我也是,怎么解决啊

@zhiben5201
Copy link

不是说新版本需要先启动什么端口服务器吗

@BrandyLeeee
Copy link

+1

@xx254

This comment was marked as spam.

@hubbylei
Copy link

出现同样的错误:HTTPConnectionPool(host='47.115.200.238', port=80): Max retries exceeded with url: /xg/path?url=sec_user_id=MS4wLjABAAAA8AIINGj240azZm5XhR7kiIcGh--VxzHoskD7gkzyw7Q%26count=35%26max_cursor=0%26aid=1128%26version_name=23.5.0%26device_platform=android%26os_version=2333 (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x000001AF59148FD0>: Failed to establish a new connection: [WinError 10061] 由于目标计算机积极拒绝,无法连接。'))

Win 11 中文 x64最新版,每次都会复现。

跪请大神出手!

你这个绝对不是最新版,xg这个已经改成本地服务了

@eightrivers
Copy link

恩,谢谢指导! 这个错误对应的确实不是最新版。我刚刷了最新版本,还是报类似的错误。错误信息如下:

image

cookie配置如下:

image

@WWRichard WWRichard changed the title Util\XB.py", line 50, in getXbogus UnboundLocalError: local variable 'response' referenced before assignment 终于解决啦!!!Util\XB.py", line 50, in getXbogus UnboundLocalError: local variable 'response' referenced before assignment Mar 31, 2023
@WWRichard
Copy link
Author

出现同样的错误:HTTPConnectionPool(host='47.115.200.238', port=80): Max retries exceeded with url: /xg/path?url=sec_user_id=MS4wLjABAAAA8AIINGj240azZm5XhR7kiIcGh--VxzHoskD7gkzyw7Q%26count=35%26max_cursor=0%26aid=1128%26version_name=23.5.0%26device_platform=android%26os_version=2333 (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x000001AF59148FD0>: Failed to establish a new connection: [WinError 10061] 由于目标计算机积极拒绝,无法连接。'))

Win 11 中文 x64最新版,每次都会复现。

跪请大神出手!

我的解决了,看上面

Johnserf-Seed added a commit that referenced this issue Aug 4, 2023
…#287 #294 #312 #320 #332 #335 #341 #343 #346 #355 #357 #360 #361 #362 #364 #365 #367 #370 #372 #374 #376 #377 #379 #380 #381 #382 #383 #393 #394 #397 #398 #399 #401 #402 #403 #404 #406 #407 #408 #410 #414 #416 #419 #420 #422 #423 #426 #431 #432 #433 #434 #435 #436 #437 #446 #448 #449 #450 #451 #452 #454 #455 #456 #567 #460 #466 #469 #470 #471 #472 #475 #476 #477 #480 #481 #483 #484 #485

1、全面升级aiohttp作为异步网络请求,asyncio为密集型IO
2、将导入的库做一个分类排序
3、新增昵称映射、登录、版本自定义模块
4、删除图集模块(现统一由Profile模块处理)
5、优化初始化控制台输出信息,由rich美化
6、偷懒欠了一屁股issues🥴
#155 #191 #202 #203 #206 #220 #226 #227 #243 #267 #287 #294 #312 #320 #332 #335 #341 #343 #346 #355 #357 #360 #361 #362 #364 #365 #367 #370 #372 #374 #376 #377 #379 #380 #381 #382 #383 #393 #394 #397 #398 #399 #401 #402 #403 #404 #406 #407 #408 #410 #414 #416 #419 #420 #422 #423 #426 #431 #432 #433 #434 #435 #436 #437 #446 #448 #449 #450 #451 #452 #454 #455 #456 #567 #460 #466 #469 #470 #471 #472 #475 #476 #477 #480 #481 #483 #484 #485
Johnserf-Seed added a commit that referenced this issue Aug 4, 2023
…294 #312 #320 #332 #335 #341 #343 #346 #355 #357 #360 #361 #362 #364 #365 #367 #370 #372 #374 #376 #377 #379 #380 #381 #382 #383 #393 #394 #397 #398 #399 #401 #402 #403 #404 #406 #407 #408 #410 #414 #416 #419 #420 #422 #423 #426 #431 #432 #433 #434 #435 #436 #437 #446 #448 #449 #450 #451 #452 #454 #455 #456 #567 #460 #466 #469 #470 #471 #472 #475 #476 #477 #480 #481 #483 #484 #485

1、重构所有逻辑改使用异步,便于个人开发调用
2、create_user_folder函数用于创建作品保存目录并返回路径
3、re_match匹配用户的唯一标识
4、get_request_data返回接口的数据
5、get_all_sec_user_id返回用户的唯一标识
6、get_diff_type_url根据传入配置文件中的mode和用户sec_user_id,生成不同作品类型的接口链接
7、get_user_base_info获取用户im基本数据
8、get_user_profile_info获取用户完整信息
9、get_user_post_info获取用户的作品信息
10、get_Profile 相当于main
#155 #191 #202 #203 #206 #220 #226 #227 #243 #267 #287 #294 #312 #320 #332 #335 #341 #343 #346 #355 #357 #360 #361 #362 #364 #365 #367 #370 #372 #374 #376 #377 #379 #380 #381 #382 #383 #393 #394 #397 #398 #399 #401 #402 #403 #404 #406 #407 #408 #410 #414 #416 #419 #420 #422 #423 #426 #431 #432 #433 #434 #435 #436 #437 #446 #448 #449 #450 #451 #452 #454 #455 #456 #567 #460 #466 #469 #470 #471 #472 #475 #476 #477 #480 #481 #483 #484 #485
Johnserf-Seed added a commit that referenced this issue Aug 4, 2023
 #320 #332 #335 #341 #343 #346 #355 #357 #360 #361 #362 #364 #365 #367 #370 #372 #374 #376 #377 #379 #380 #381 #382 #383 #393 #394 #397 #398 #399 #401 #402 #403 #404 #406 #407 #408 #410 #414 #416 #419 #420 #422 #423 #426 #431 #432 #433 #434 #435 #436 #437 #446 #448 #449 #450 #451 #452 #454 #455 #456 #567 #460 #466 #469 #470 #471 #472 #475 #476 #477 #480 #481 #483 #484 #485

1、引入了 "update" 参数来决定是否每次进行版本更新
2、自定义URL常量,方便修改
3、使用 os.path.join() 代替手动拼接路径,以提高跨平台兼容性
4、提取了进度条显示功能,简化了 zip_Download 方法
5、优化了对用户输入的处理,改用循环重新询问,直到用户输入有效值为止
6、使用 shutil.move() 和 shutil.rmtree() 代替 os.rename() 和 os.removedirs(),以解决部分情况下无法移动或删除文件的问题
#155 #191 #202 #203 #206 #220 #226 #227 #243 #267 #287 #294 #312 #320 #332 #335 #341 #343 #346 #355 #357 #360 #361 #362 #364 #365 #367 #370 #372 #374 #376 #377 #379 #380 #381 #382 #383 #393 #394 #397 #398 #399 #401 #402 #403 #404 #406 #407 #408 #410 #414 #416 #419 #420 #422 #423 #426 #431 #432 #433 #434 #435 #436 #437 #446 #448 #449 #450 #451 #452 #454 #455 #456 #567 #460 #466 #469 #470 #471 #472 #475 #476 #477 #480 #481 #483 #484 #485
Johnserf-Seed added a commit that referenced this issue Dec 31, 2023
…#220 #223 #230 #242 #258 #260 #295 #312 #313 #320 #322 #332 #335 #341 # #343 #346 #348 #355 #357 #360 #361 #362 #364 #367 #370 #372 #373 #374 #376 #377 #379 #380 #381 #382 #383 #393 #394 #395 #396 #398 #399 #400 #401 #402 #403 #404 #405 #407 #408 #410 #412 #414 #416 #423 #424 #426 #432 #435 #438 #442 #443 #449 #450 #455 #456 #457 #459 #460 #465 #467 #470 #472 #473 #474 #475 #481 #482 #483 #488 #492 #493 #499 #502 #503 #504 #505 #507 #509 #512 #514 #524 #525 #530 #539 #540 #541 #547 #550 #554 #558 #563 #568 #569 #572 #574 #575 #576 #577 #578 #582 #583 #584 #587 #589 #590 #594 #595 #597 #598 #600 #601 #604 #605 #606 #608 #611 #617 #618 #619

[Added]
1. 新增了对直播间信息的详细获取和下载功能。
2. 添加详细直播间信息的下载支持。
3. 引入了提取评论的功能。
4. 新增支持下载 TikTok 数据,包括发布作品、喜欢作品、图集作品等。
5. 提供了自动生成 XB 参数的接口,支持真实和虚假的 msToken。
6. 引入接口数据过滤器,提高数据采集和处理效率。
7. 增加支持长短链解析的功能。
8. 新增了对合集作品的详细获取和下载功能。
9. 引入了 SSO 扫码登录和自动获取Cookie的功能,可通过 `--auto-cookie` 参数实现。

[Changed]
1. 优化了异步下载的网络并发数、超时重试设置,降低采集错误率。
2. 修改了文件检查逻辑,添加了黑名单选项,不再检查黑名单中的作品是否存在。(未来)
3. 对命令行交互进行了调整,添加了更多的配置选项,提供了更灵活的 CLI 模式。
4. 改进了版本更新机制,全新开发的 F2 现在依赖 pip 进行升级。
5. 对于多用户配置,现在可以为不同用户建立不同的配置与下载模式。

[Security]
1. 修复了可能导致信息泄露的漏洞。

[Deprecated]
1. 废弃了一些低版本接口的相关功能,建议使用更新的接口。

[Fixed]
1. 修复了一些在异步下载中可能导致的错误。
2. 修复了一些异步下载线程控制的错误。

[Removed]
1. 移除了不再支持的功能和接口。

[Documentation]
1. 更新了文档,提供了更详细的配置和使用说明。
2. 补充了开发者必读的内容,包括配置文件、调试日志级别等。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
故障(bug) 代码问题导致的错误(Bugs caused by code problems) 额外求助(help wanted) 非项目代码错误的求助(Extra attention is needed) 无效(invalid) 非代码故障导致错误或异常(Non-code faults causing errors or anomalies)
Projects
None yet
Development

No branches or pull requests

9 participants