Oct-18-2017, 02:24 PM
(This post was last modified: Oct-18-2017, 03:21 PM by sonicblind.)
Hi,
I am struggling with smc-python library - frontend to Stonegate API.
To create a session with the API I should simply use:
When I run a script with this login I receive Exception:
So I tried to execute this function directly and wrote this small test script:
And the result:
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 :-)
I am struggling with smc-python library - frontend to Stonegate API.
To create a session with the API I should simply use:
1 |
|
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:1 2 3 4 |
def get_entry_points(base_url, timeout = 10 , verify = True ): try : r = requests.get( '%s/api' % (base_url), timeout = timeout, verify = verify) ....... |
1 2 3 4 5 6 7 8 |
try : 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)) |
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 :-)