-2

I want to get data from a web service. For this use the following URL on Postman:

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

And I have to add a raw in Postman (Body->raw) like the following to verify user:

    {
    "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"
}

When I use Postman I can get data. When I use Python request with Django:

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)

I got error:

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',))

How can solve this problem?

UYAR.C
  • 151
  • 2
  • 10
  • A bit of google search "how to make an http request in python" gives you plenty of results. This question shows you haven't really made any effort to find an answer. – dirkgroten Mar 04 '20 at 15:08
  • Does this answer your question? [How to send a POST request using django?](https://stackoverflow.com/questions/5308060/how-to-send-a-post-request-using-django) – Ryanman Mar 04 '20 at 17:58
  • @dirkgroten I tried to handle this problem using the python request. I get the error even though I have my security permissions all over the network to use. I asked this question because I thought it might be another structure I should have ignored or used. Thank you for your understanding answer. – UYAR.C Mar 05 '20 at 06:27
  • @Ryanman I edited question. – UYAR.C Mar 05 '20 at 07:19
  • 1
    The error tells you that you can't reach the server. So it doesn't have much to do with how you make the request. Open a django shell (`manage.py shell`) on the same machine where your django app is running and try the request from your shell, you'll probably find the same problem. Check your network to see why you can't reach the api server. – dirkgroten Mar 05 '20 at 09:54

1 Answers1

1

You can make a request using python request: Python Requests

Pablo
  • 364
  • 1
  • 10
  • Thanks. I edited the question. To better explain my problem. – UYAR.C Mar 05 '20 at 07:20
  • You probably have to open a session to later make the call to that url. s = requests.Session() --> s.get('http://x.x.x.x:8090/api/jserv.ashx') --> r=s.post(url, params=params, data=json.dumps(data), headers=headers) – Pablo Mar 06 '20 at 11:07