0

I have the following working curl command:

curl -x http://<PROXY URL>:3128 -u myUsername 'https://logs.company.net/daily-2017.04.13/_search?pretty' -d '{BIG JSON BLOB}

I am trying to convert that into python using the requests library. Here is what I have so far:

json_string = '''{BIG JSON BLOB}'''

print(json_string)
mydict = json.loads(json_string)    # obj now contains a dict of the data

proxies = {"http" : "http://<proxy url>:3128"}
r = requests.get("https://logs.company.net/daily-2017.04.13/_search?pretty", data=json_string,auth=(self.username, self.password), proxies=proxies, verify= False) #
print(r.status_code, r.reason)
print(str(r.content))

From what I understand this is basically identical to the above, but it times out on my test server when the curl command does not.

Does anyone know what the problem is here or how I can debug it? I could have hacked in the curl command using the subprocess module but I am pretty new to debugging networking stuff and I want to learn why it is not working hence deciding to ask here.

Thanks!

Jaroslav Bezděk
  • 6,967
  • 6
  • 29
  • 46

1 Answers1

0

According to the manual page of curl command, the -d flag is used to post data using the POST request:

-d/--data

(HTTP) Sends the specified data in a POST request to the HTTP server, in the same way that a browser does when a user has filled in an HTML form and presses the submit button. This will cause curl to pass the data to the server using the content-type application/x-www-form-urlencoded. Compare to -F/--form.

So, you need to use requests.post() function instead of requests.get().

For instance:

r = requests.post("https://logs.company.net/daily-2017.04.13/_search?pretty",
                  data=json_string,
                  auth=(self.username, self.password),
                  proxies=proxies,
                  verify=False)
Laurent LAPORTE
  • 21,958
  • 6
  • 58
  • 103