为什么我使用request和json模块在Python中收到此错误?

时间:2015-08-16 20:59:27

标签: python json python-requests

我一直在尝试在python中处理几千个请求,然后将它们写入json文件。出于某种原因,每当我运行我的代码时,我都会收到以下错误:

File "C:\Program Files (x86)\Wing IDE 101 5.1\src\debug\tserver\_sandbox.py", line 133, in <module>
File "C:\Program Files (x86)\Wing IDE 101 5.1\src\debug\tserver\_sandbox.py", line 44, in main
File "E:\Python Programs\API Challenge Aug 2015\API Challenge Files\Execute Requests Files\RiotAPI.py", line 112, in get_match_by_matchid
 return self._request(api_url, region)
File "E:\Python Programs\API Challenge Aug 2015\API Challenge Files\Execute Requests Files\RiotAPI.py", line 58, in _request
 return response.json()
File "C:\Python\Lib\site-packages\requests\models.py", line 819, in json
 return json.loads(self.text, **kwargs)
File "C:\Python\Lib\json\__init__.py", line 318, in loads
 return _default_decoder.decode(s)
File "C:\Python\Lib\json\decoder.py", line 343, in decode
 obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "C:\Python\Lib\json\decoder.py", line 361, in raw_decode
 raise ValueError(errmsg("Expecting value", s, err.value)) from None
builtins.ValueError: Expecting value: line 1 column 1 (char 0)

请注意,错误将发生在看似随机数量的请求之后。有时它会在10个请求之后发生,有时它会在错误发生之前持续几百个请求。我已经详尽地尝试了这一点,并且在一次请求数量相同之后它没有被破坏。

我正在使用的导致此错误的文件与您在此处可以看到的帖子的方法相同:What am I doing wrong with requests in python: ValueError: Expecting value: line 1 column 1 (char 0)?

我相信我的错误来自你在该帖子中会发现的同一个问题,但据我所知,答案从未被发现。任何人都可以帮我解决这个问题吗?

0 个答案:

没有答案