找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 77|回复: 0

[求助] JSONDecodeError: Expecting value: line 1 column 1 (char 0)

2

主题

2

帖子

2

积分

贫民

积分
2
oushitianxia 发表于 2019-7-11 16:06:17 | 显示全部楼层 |阅读模式
报错信息如下、
>python.exe tickets.py -gd 长沙 昆明 2019-09-10
Traceback (most recent call last):
  File "tickets.py", line 45, in <module>
    cli()
  File "tickets.py", line 42, in cli
    available_trains = r.json()['data']['result']
  File "C:\Users\beckh\PycharmProjects\untitled\venv\lib\site-packages\requests\models.py", line 897, in json
    return complexjson.loads(self.text, **kwargs)
  File "C:\Users\beckh\AppData\Local\Programs\Python\Python36\lib\json\__init__.py", line 354, in loads
    return _default_decoder.decode(s)
  File "C:\Users\beckh\AppData\Local\Programs\Python\Python36\lib\json\decoder.py", line 339, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "C:\Users\beckh\AppData\Local\Programs\Python\Python36\lib\json\decoder.py", line 357, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)


源代码如下、
def cli():
     """command-line interface"""
     arguments = docopt(__doc__)
     # 根据命令行用输入的起始车站名称、日期,查询stati**中对应的英文代码
     from_station = stati**.get(arguments['<from>'])
     to_station = stati**.get(arguments['<to>'])
     date = arguments['<date>']

     # 发起请求查询车次信息
     url = 'https://kyfw.12306.cn/otn/leftTicket/query?leftTicketDTO.train_date={}&leftTicketDTO.from_station={}&leftTicketDTO.to_station={}&purpose_codes=ADULT'.format(date, from_station, to_station)
     r = requests.get(url)
     # 将返回的json数据转为字典类型
     # 其中车次信息在返回的字典键为data的值嵌套的字典中,其嵌套的键为result的值中
     available_trains = r.json()['data']['result']


我在PyCharm上测试没问题呀
url='https://kyfw.12306.cn/otn/leftTicket/query?leftTicketDTO.train_date=2019-07-21&leftTicketDTO.from_station=CSQ&leftTicketDTO.to_station=NDC&purpose_codes=ADULT'
r=requests.get(url)
print(r.json()['data']['result'])['CGxsVJKpNwn8WZqVhP8VLRcwaOpaqYWmHqk0wkJ0RXl%2BWZASxrw8%2FVEFYQaLgBC8Vbg3l7DwOTlg%0A39Poa1EzPE%2BM3OxfuVpwZnQgCMDtEkUGDn4i3oobIy3gKuU7vS7gLxCsUrvK7q9zyw66yQz8YiXu%0A9LizxqVzAWJg%2B0SzOTu3Y%2FlbAltaLraG2Suu7ihHETtNxagZ19Cqg25oQRhbqi80BjP2wKFfZO4q%0A%2FffEh0eLBIQcLQjzeaI%2FMpWpEpwRE9Z4s4Eue1ViSSwrxVDIjD6caA5zYd0CpWSelbC0s8qvPpUp%0AjWbvtQEi68g%3D|预订|710000Z33607|Z336|NNZ|BTC|CSQ|HHC|19:22|21:14|25:52|Y|cUe4yMMeLNWGcvjmEAUxcGk2aadz84Doni1V6hZS4uqEQMPc0wopdQoGneo%3D|20190721|3|Z1|05|19|0|0||||无|||有||无|无|||||10401030|1413|0|1|', 'bUeNvZ7hxURP%2BEBa2ap3C84Tqpht7K6l%2BSSt944zBBiWlGVg7IdM9c8U9PSe%2BNaGJPvcwril1FqI%0AjdYtb7TEDrbDoyPegKQFahZn6vWJCpRbLOHk3cpCQ0jAk%2FSgXlqBnB7IlUoJVIxqG49AkDMvdGUh%0Ac4FDAv3s9YJ6MPFQb9sE2GN83aZJ2ef%2FcZjCqhsJ0ToktJ14WyeWIwGfUkP4oY0BA15i%2Bji6u175%0AslFVrPEZTCvWBn7OkHlf4wl0hFUXpdjviik5pG8K5%2BMwa6OdJJydvKguXUNhoZXeL9yp1enZEoxG%0Aqm8yVJDkKnexSRhX|预订|630000K6000I|K600|GZQ|BTC|CSQ|NDC|23:23|06:52|31:29|Y|O%2Bpy6URUXwdJhOpxJ6ioOYa%2FeSjo9dR6r7nmHSGPyNH17RIbbpqqF4Fi17Y%3D|20190721|3|Q6|06|32|0|0||||无|||有||无|有|||||10401030|1413|0|1|']

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表