James He
2018-12-27 16:39
采纳率: 100%
浏览 9.8k

12306抢票打包exe报错json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

环境win7python3.7pyinstaller3.4代码是网上参考的,功能性不影响,但是在用pyinstaller打包的时候会报错。源代码如下:

# coding=utf-8
from splinter.browser import Browser
from time import sleep
import traceback
user_name = input("账号")
password = input("密码")
# 账号密码
d_time = u"2019-01-04"
starts = u"%u4E0A%u6D77%2CSHH"
ends = u"%u6606%u660E%2CKMM"
order = 1
ticket_url = u"https://kyfw.12306.cn/otn/leftTicket/init"
login_url = u"https://kyfw.12306.cn/otn/login/init"
initmy_url = u"https://kyfw.12306.cn/otn/view/index.html"


def login():
    b.find_by_text(u"登录").click()
    sleep(3)
    b.find_by_text(u"账号登录").click()
    sleep(0.5)
    b.find_by_id(u"J-userName").fill(user_name)
    sleep(1)
    b.find_by_id(u"J-password").fill(password)
    sleep(1)
    print(u"自己手动选择验证码图片并且点击登录")
    while True:
        if b.url != initmy_url:
            sleep(1)
        else:
            break


def huo_che():
    global b
    b = Browser(driver_name="chrome")
    b.visit(ticket_url)
    while b.is_text_present(u"登录"):
        sleep(1)
        login()
        if b.url == initmy_url:
            break
    try:
        print(u"购票页面...")
        # 跳回购票页面
        b.visit(ticket_url)
        # 加载查询信息
        b.cookies.add({u"_jc_save_fromStation": starts})
        b.cookies.add({u"_jc_save_toStation": ends})
        b.cookies.add({u"_jc_save_fromDate": d_time})
        b.reload()
        sleep(2)
        count = 0
        # 循环点击预订
        if order != 0:
            while b.url == ticket_url:
                b.find_by_text(u"查询").click()
                count += 1
                print(u"循环点击查询... 第 %s 次" % count)
                sleep(1)
                try:
                    b.find_by_text(u"预订")[order-1].click()
                    break
                except Exception as e:
                    print(e)
                    continue
        else:
            while b.url == ticket_url:
                b.find_by_text(u"查询").click()
                count += 1
                print(u"循环点击查询... 第 %s 次" % count)
                sleep(1)
                try:
                    for i in b.find_by_text(u"预订"):
                        i.click()
                except Exception as e:
                    print(e)
                    continue
        b.find_by_id(u"normalPassenger_0").click()
        b.find_by_id(u"submitOrder_id").click()
        sleep(0.5)
        b.find_by_id(u"qr_submit_id").click()
        print(u"自行支付")
    except Exception as e:
        print(e)
        print(traceback.print_exc())


if __name__ == "__main__":
    huo_che()

打包时候报错:
13737 WARNING: Cannot read QLibraryInfo output: raised Expecting value: line 1 column 1 (char 0) when decoding:
Traceback (most recent call last):
File "", line 11, in
ImportError: DLL load failed: 找不到指定的程序。
Traceback (most recent call last):
File "D:\python\Scripts\pyinstaller-script.py", line 11, in
load_entry_point('PyInstaller==3.4', 'console_scripts', 'pyinstaller')()
File "d:\python\lib\site-packages\PyInstaller__main__.py", line 111, in run
run_build(pyi_config, spec_file, **vars(args))
File "d:\python\lib\site-packages\PyInstaller__main__.py", line 63, in run_build
PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
File "d:\python\lib\site-packages\PyInstaller\building\build_main.py", line 838, in main
build(specfile, kw.get('distpath'), kw.get('workpath'), kw.get('clean_build'))
File "d:\python\lib\site-packages\PyInstaller\building\build_main.py", line 784, in build
exec(text, spec_namespace)
File "", line 17, in
File "d:\python\lib\site-packages\PyInstaller\building\build_main.py", line 241, in init
self.__postinit__()
File "d:\python\lib\site-packages\PyInstaller\building\datastruct.py", line 158, in postinit
self.assemble()
File "d:\python\lib\site-packages\PyInstaller\building\build_main.py", line 500, in assemble
module_hook.post_graph()
File "d:\python\lib\site-packages\PyInstaller\building\imphook.py", line 410, in post_graph
self._load_hook_module()
File "d:\python\lib\site-packages\PyInstaller\building\imphook.py", line 377, in load_hook_module
self.hook_module_name, self.hook_filename)
File "d:\python\lib\site-packages\PyInstaller\compat.py", line 736, in importlib_load_source
return mod_loader.load_module()
File "", line 407, in _check_name_wrapper
File "", line 907, in load_module
File "", line 732, in load_module
File "", line 265, in _load_module_shim
File "", line 696, in _load
File "", line 677, in _load_unlocked
File "", line 728, in exec_module
File "", line 219, in _call_with_frames_removed
File "d:\python\lib\site-packages\PyInstaller\hooks\hook-PyQt5.py", line 23, in
collect_system_data_files(pyqt5_library_info.location['PrefixPath'],
File "d:\python\lib\site-packages\PyInstaller\utils\hooks\qt.py", line 67, in __getattr
_
qli = json.loads(json_str)
File "d:\python\lib\json__init__.py", line 348, in loads
return _default_decoder.decode(s)
File "d:\python\lib\json\decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "d:\python\lib\json\decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • James He 2018-12-29 03:37
    已采纳

    新建一个虚拟环境重新安装pyinstaller就可以了

    点赞 评论
  • blownewbee 2018-12-27 09:13

    这种程序,不同于人家正规给你接口的,属于私自写的爬虫。12306一改版自然json解析不起来,程序就出错了。

    要么你学会抓包去写,否则人家的代码等你看到再来用,还能用的基本上不可能

    点赞 1 评论

相关推荐 更多相似问题