最新消息:20210917 已从crifan.com换到crifan.org

【已解决】Python代码报错:json.decoder.JSONDecodeError Expecting value line 1 column 1 char 0

Python crifan 3284浏览 0评论
折腾:
【未解决】批量测试安卓游戏:ViVo的Game的搜魔幻且是即时战斗类的游戏20201202
期间,遇到报错:
[201202 16:39:37][AppCrawler.py 90 ] Expecting value: line 1 column 1 (char 0)
    Traceback (most recent call last):
      File "/Users/xxx/dev/xxx/crawler/appAutoCrawler/AppCrawler/src/AppCrawler.py", line 84, in start
        self.set_InitialUrl()
      File "/Users/xxx/dev/xxx/crawler/appAutoCrawler/AppCrawler/src/AppCrawler.py", line 158, in set_InitialUrl
        self.doGameAutoTest()
      File "/Users/xxx/dev/xxx/crawler/appAutoCrawler/AppCrawler/src/AppCrawler.py", line 788, in doGameAutoTest
        self.fromHomeToPayment()
      File "/Users/xxx/dev/xxx/crawler/appAutoCrawler/AppCrawler/src/AppCrawler.py", line 328, in fromHomeToPayment
        while not self.isGotoPayPopupPage_multipleRetry():
      File "/Users/xxx/dev/xxx/crawler/appAutoCrawler/AppCrawler/src/common/MainUtils.py", line 5316, in isGotoPayPopupPage_multipleRetry
        respBoolOrTuple = CommonUtils.multipleRetry(
      File "/Users/xxx/dev/xxx/crawler/appAutoCrawler/AppCrawler/utils/common_utils.py", line 695, in multipleRetry
        respValue = functionCallback(**functionParaDict)
      File "/Users/xxx/dev/xxx/crawler/appAutoCrawler/AppCrawler/src/common/MainUtils.py", line 5349, in isGotoPayPopupPage
        respBoolOrTuple = self.isExistAnyStr(gotoPayStrList, isRespFullInfo=isRespLocation)
      File "/Users/xxx/dev/xxx/crawler/appAutoCrawler/AppCrawler/src/common/BaiduOCR.py", line 889, in isExistAnyStr
        checkResult = self.checkExistInScreen(
      File "/Users/xxx/dev/xxx/crawler/appAutoCrawler/AppCrawler/src/common/BaiduOCR.py", line 818, in checkExistInScreen
        wordsResultJson = self.baiduImageToWords(imgPath)
      File "/Users/xxx/dev/xxx/crawler/appAutoCrawler/AppCrawler/src/common/BaiduOCR.py", line 97, in baiduImageToWords
        respJson = resp.json()
      File "/Users/xxx/dev/xxx/crawler/appAutoCrawler/AppCrawler/venv/lib/python3.8/site-packages/requests/models.py", line 897, in json
        return complexjson.loads(self.text, **kwargs)
      File "/Users/xxx/.pyenv/versions/3.8.0/Python.framework/Versions/3.8/lib/python3.8/json/__init__.py", line 357, in loads
        return _default_decoder.decode(s)
      File "/Users/xxx/.pyenv/versions/3.8.0/Python.framework/Versions/3.8/lib/python3.8/json/decoder.py", line 337, in decode
        obj, end = self.raw_decode(s, idx=_w(s, 0).end())
      File "/Users/xxx/.pyenv/versions/3.8.0/Python.framework/Versions/3.8/lib/python3.8/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)
去找找报错代码
        resp = requests.post(self.OCR_URL, params=paramDict, headers=headerDict, data=dataDict)
        respJson = resp.json()
看起来是:
此处resp.json()报错的
且resp中是空的
导致无法json解码
所以可以:
最完美的是:
加上try和catch
或者是判断此处resp.text,不空,再去调用
还是用保险的try和catch吧
发现是try和except
python try except
Python Try Except
8. 错误和异常 — Python 3.9.1rc1 文档
改为:
        try:
            respJson = resp.json()
        except JSONDecodeError as jsonDecodeErr:
            logging.error("resp str: %s, json decode error: %s, ", resp.text, str(jsonDecodeErr))
            respJson = {}
估计就可以了。
待后续遇到了,再去调试。
不过去看看log,或许会有resp的细节?
有log,但没resp的细节,尤其是text。所以无法回溯问题了。
待后续遇到再说。

转载请注明:在路上 » 【已解决】Python代码报错:json.decoder.JSONDecodeError Expecting value line 1 column 1 char 0

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
92 queries in 0.189 seconds, using 23.37MB memory