dqxsuig64994 2016-11-21 05:58 采纳率: 0%
浏览 97

如何使用python中的HTTPrequests库从我的php本地服务器返回json数据?

My Python script:

import requests
import json
location = '127.0.0.1'
port = 8000

# Setup the REST API URL string
apiString = 'http://' + location + ':' + str(port) + '/edsa-Python/Matrix_mult_dynamic/run_python.php'
print apiString

#Make the REST API Request
resp = requests.get(apiString)
print resp.text
# print resp.encoding

# Get the JSON that is returned
if resp.status_code == requests.codes.ok:
    the_json = resp.json()
    #print the_json

Error: I get an error saying that No JSON object could be decoded. Below is the error that I get when I run the python script in the command prompt:

http://127.0.0.1:8000/edsa-Python/Matrix_mult_dynamic/run_python.php

Traceback (most recent call last):
  File "client_python.py", line 25, in <module>
    the_json = resp.json()
  File "C:\Python27\lib\site-packagesequests-2.12.0-py2.7.eggequests\models.py", line 841, in json
    return complexjson.loads(self.text, **kwargs)
  File "C:\Python27\lib\json\__init__.py", line 339, in loads
    return _default_decoder.decode(s)
  File "C:\Python27\lib\json\decoder.py", line 364, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "C:\Python27\lib\json\decoder.py", line 382, in raw_decode
    raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 使用EMD去噪处理RML2016数据集时候的原理
    • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
    • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
    • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
    • ¥15 如何在炒股软件中,爬到我想看的日k线
    • ¥15 seatunnel 怎么配置Elasticsearch
    • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
    • ¥15 (标签-MATLAB|关键词-多址)
    • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
    • ¥500 52810做蓝牙接受端