解決錯誤——TypeError the JSON object must be str, not bytes

1. 錯誤

Traceback (most recent call last):
  File "spider.py", line 83, in <module>
    runSpider('games')
  File "spider.py", line 74, in runSpider
    for url in urls:
  File "spider.py", line 35, in getNewsUrl
    data = json.loads(response.content)
TypeError: the JSON object must be str, not 'bytes'

2. 解決

將 json.loads(lines) 修改爲  json.loads(lines.decode()) 即可解決。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章