【发布时间】:2020-03-04 13:37:44
【问题描述】:
我想从网络服务获取数据。为此,请在 Postman 上使用以下 URL:
http://x.x.x.x:8090/api/jserv.ashx?action=ReportMethod // has a paramater
我必须在 Postman (Body->raw) 中添加一个 raw ,如下所示来验证用户:
{
"user": {
"userid": "35acf0eb-084c-4328-a022-fbdddb419873",
"username": "User",
"status": false,
"mesaj": null,
"masterno": 0,
"versiyon": null
},
"start": "1900-01-01T00:00:00",
"end": "2020-02-25T00:00:00"
}
当我使用 Postman 时,我可以获取数据。当我在 Django 中使用 Python 请求时:
headers = {'content-type': 'application/json'}
url = 'http://x.x.x.x:8090/api/jserv.ashx'
params = {'action': 'ReportMethod'}
data = {"user": { "userid": "xxxx","username": "User","status": "false","mesaj": "null","masterno": 0,"versiyon": "null"},"start": "1900-01-01T00:00:00","end": "2020-02-25T00:00:00"}
r = requests.post(url, params=params, data=json.dumps(data), headers=headers)
我收到错误:
HTTPConnectionPool(host='x.x.x.x', port=8090): Max retries exceeded with url: /api/jserv.ashx?action=ReportMethod (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f4649c98eb8>: Failed to establish a new connection: [Errno 110] Connection timed out',))
如何解决这个问题?
【问题讨论】:
-
一点谷歌搜索“如何在 python 中发出 http 请求”会给你很多结果。这个问题表明你并没有真正努力寻找答案。
-
这能回答你的问题吗? How to send a POST request using django?
-
@dirkgroten 我尝试使用 python 请求来处理这个问题。即使我在整个网络上都有我的安全权限可以使用,我也会收到错误消息。我问这个问题是因为我认为它可能是我应该忽略或使用的另一种结构。感谢您的理解回答。
-
@Ryanman 我编辑了问题。
-
错误告诉你无法访问服务器。因此,这与您提出请求的方式没有太大关系。在运行 django 应用程序的同一台机器上打开一个 django shell (
manage.py shell) 并尝试来自 shell 的请求,你可能会发现同样的问题。检查您的网络,看看为什么您无法访问 api 服务器。