Python Forum
Error getting HTTP 200 response with requests.get while wget works fine
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Error getting HTTP 200 response with requests.get while wget works fine
#1
Hi,

I am struggling with smc-python library - frontend to Stonegate API.

To create a session with the API I should simply use:
session.login(url='http://1.1.1.1:8082', api_key='xxxxxxxxxxxxxxxxx')
When I run a script with this login I receive Exception:

Output:
user@script:~$ ./smc_api.py Traceback (most recent call last): File "./smc_api.py", line 51, in <module> xxxxxxx File "/usr/local/lib/python3.5/dist-packages/smc/api/session.py", line 214, in login self._api_version = get_api_version(url, api_version, timeout, verify) File "/usr/local/lib/python3.5/dist-packages/smc/api/session.py", line 381, in get_api_version versions = available_api_versions(base_url, timeout, verify) File "/usr/local/lib/python3.5/dist-packages/smc/api/session.py", line 368, in available_api_versions 'Status code received %s. Reason: %s' % (r.status_code, r.reason)) smc.api.exceptions.SMCConnectionError: Invalid status received while getting entry points from SMC. Status code received 404. Reason: Not Found
When I trace the function available_api_versions it basically does a request as follows:
def get_entry_points(base_url, timeout=10, verify=True):
    try:
        r = requests.get('%s/api' % (base_url), timeout=timeout, verify=verify)
        .......
So I tried to execute this function directly and wrote this small test script:
try:
	r = requests.get('http://1.1.1.1:8082/api')
	if r.status_code == 200:
		print('success')
	else:
		raise Exception('Status code received %s. Reason: %s' % (r.status_code, r.reason))
except Exception as ex:
	print("An exception of type {0} occurred. Arguments:\n{1!r}".format(type(ex).__name__, ex.args))
And the result:
Output:
user@server:~$ ./test.py An exception of type Exception occurred. Arguments: ('Status code received 404. Reason: Not Found',)
So my issue is that wget is actually able to get a response from API while the requests.get is not.

WORKS: wget -qO- http://1.1.1.1:8082/api
DOES NOT WORK: r = requests.get('http://1.1.1.1:8082/api')

Proxy settings are not an issue, both requests are able to reach the API.
But while the wget gets HTTP/200 response with actual data, requests.get receives HTTP/404 not found.

What am I missing here? What is different? I would assume both wget and requests.get should behave the same way when exactly the same URL is provided as parameter.

Any advice very welcome!
Thanks.

One small correction. I've made a typo in the function name.
It should be available_api_versions instead of get_entry_points.
But it does not matter anyway as both functions are doing the same request:
r = requests.get('%s/api' % base_url, timeout=timeout, verify=verify)

!!!MY MISTAKE!!!
It was indeed the problem with Proxy. requests.get was using the system proxy and the HTTP/404 was actually a reply from the proxy.
Problem solved :-)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to send a HTTP response packet using scapy JeffreyStoner 0 2,678 Apr-18-2022, 05:23 AM
Last Post: JeffreyStoner
  WSAStartup error with requests yllawwally 1 3,012 Feb-23-2021, 01:53 PM
Last Post: yllawwally
  Http connection error when using API request (requests library) zazas321 1 3,091 Oct-13-2020, 05:58 AM
Last Post: zazas321
  Test http requests JohnnyCoffee 2 2,385 Jul-10-2020, 03:14 AM
Last Post: JohnnyCoffee
  Configuring requests module to use secondary IP on server for outbound requests mohit 1 6,618 Oct-24-2016, 05:21 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020