How to fix requests.get() failure on gitlab rest api? - python

I am using python reqests.get() to invoke one of gitlab api's in my Python script running on Windows. It works fine on my dev machine, but it fails with below error message when I run the script in TeamCity job runner.
HTTPSConnectionPool(host='gitlab.myservice.com', port=443): Max retries exceeded with url: /api/v4/projects/1111/pipeline_schedules/111?private_token=******* (Caused by SSLError(SSLError(1, '_ssl.c:503: error:14077410:SSL routines:SSL23_GET_SERVER_HELLO:sslv3 alert handshake failure'),))
What is very strange is that very similar script that calls Artifactory rest api runs just fine in the same script even when it runs in TeamCity.
Can anybody shed light on this mystery?
Update
The infra is using Python 2.7.16. When I tested with Python 3.x it worked fine. However, the org is not ready to move to 3.x due to dependencies they cannot solve yet.

Related

How to run a Python 3 script in OWASP ZAP?

I'm using ZAP to run a scan of a website from the command line, using the form-based authentication script found in the ZAP API Documentation.
java -jar ./zap-2.11.1.jar -script ./auth_script.py
However, it looks like ZAP uses Jython 2.7 instead of Python 3, so running the script this way doesn't work.
I've also tried running the script directly (i.e. python3 auth_script.py), but it throws the following error:
requests.exceptions.ProxyError: HTTPConnectionPool(host='127.0.0.1', port=8080): Max retries exceeded with url: http://zap/JSON/context/action/includeInContext/?contextName=context&regex=https%3A%2F%2Fwebsite.com%2F&apikey=9qFbZD4udTzFVYo0u5UzkZX9iuzbdcJDRAquTfRk
(Caused by ProxyError('Cannot connect to proxy.', RemoteDisconnected('Remote end closed connection without response')))
Has anyone used this form-based authentication script before? How did you get it to work?

After Internet Outage, Python can't request API endpoints properly

Basically there was an internet outage yesterday, and I tried to run my FastAPI python backend which calls API endpoints, I was getting this error during the outage and wasn't surprised since I had no internet.
However, now that i've got internet back, the API's are still not requesting properly ( Other developers i'm working with who didn't face this outage have no problems)
requests.exceptions.ConnectTimeout: HTTPSConnectionPool(host='www.api.com', port=443): Max retries exceeded with url: /filter/professor/?&page=5&filter=teacherlastname_sort_s+asc&query=*%3A*&queryoption=TEACHER&queryBy=schoolId&sid=4714 (Caused by ConnectTimeoutError(<urllib3.connection.HTTPSConnection object at 0x00000184D99C0D00>, 'Connection to www.api.com timed out. (connect timeout=5)'))
What I tried:
Re-installed all pip requirements
Re-installing the repo ( New virtual environment)
I was trying to look online, and people say some config files might have corrupted, still unsure abt this

Running Script from Command Line vs. Anaconda/Spyder/Jupyter environment

I have a script that connects to the TD Ameritrade API (I have a developer account and a margin account).
I created a script to pull some information from there and it works perfectly when I run from Jupyter or Spyder, but when I try to run from command line, I get the below error:
(Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available."))
What is causing this to happen?
Is it possible to automate scripts within Jupyter itself?
I am running from the command line because I would like to put the script on a schedule and as far as I know I would have to test my code from command line before setting it to run automatically.

Python SSL Problem with PIP, Requests and Other

I've got a problem with a SSLError that appeared since last week.
I've used Python on my machine for a few years without any problem, but now whenever i try to use a library that connects to the web, a SSLError is thrown.
I've tried other solutions to make PIP and Requests work while avoiding the certificate check, but now i need to make it work to use an Azure library.
I know it's not a problem of the Wifi connection i'm using because it works fine on other machines. Could it be something i've installed on the machine? Maybe a VPN? Is there a way to check what is "blocking" the connection?
This is an example of the error when using the Azure Iot Hub library:
ClientRequestError: Error occurred in request., SSLError: HTTPSConnectionPool(host='iothubstreamdemo.azure-devices.net', port=443): Max retries exceeded with url: /devices?api-version=2020-03-01 (Caused by SSLError(SSLError(0, 'unknown error (_ssl.c:3622)'),))
And this is while using requests:
SSLError: HTTPSConnectionPool(host='example.com', port=443): Max retries exceeded with url: / (Caused by SSLError(SSLError(0, 'unknown error (_ssl.c:3622)'),))
Thanks in advance.

SSL Errors when uploading py file to proxy server via Twine

I have packaged up a python application using python setup.py sdist bdist_wheelon an Ubuntu machine.
I want to upload these files to a proxy server of Artifactory. I am using the following twine command to do it
twine upload --repository-url https://apro.example.net.au/api/pypi/example-python -u username -p password dist/* --client-cert /usr/lib/ssl/certs/my_cert.pem
When I run the command I am getting the following error
SSLError: HTTPSConnectionPool(host='apro.example.net.au', port=443): Max retries exceeded with url: /api/pypi/example-python (Caused by SSLError(SSLError(336265225, '[SSL] PEM lib (_ssl.c:2959)'),))
I have placed my my_certs.pem into /usr/lib/ssl/certs/ and ran update-ca-certificates to make sure the certificates are up to date.
When I was trying to figure out what the SSLError was I came across what line it was complaining in _ssl.c in cpython (https://github.com/python/cpython/blob/master/Modules/_ssl.c)
What does SSL_TLSEXT_ERR_OK exact mean? I cannot figure out what is wrong with the certificate as it works fine with other applications I run against it.
Turns out my proxy server of Artifactory was having issues with certificates

Categories