Django像邮递员一样发送请求

时间:2020-03-04 13:37:44

标签: python django wsdl

我想从Web服务获取数据。为此,请在邮递员上使用以下URL:

http://x.x.x.x:8090/api/jserv.ashx?action=ReportMethod // has a paramater

我必须像下面这样在Postman中添加原始文件(Body-> 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"
}

使用邮递员时,我可以获取数据。当我在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',))

如何解决这个问题?

1 个答案:

答案 0 :(得分:1)

您可以使用python request发出请求: Python Requests

相关问题