Getting requests.exceptions.SSLError when using post in python requests

Question:

I’m using requests to post data to this Auth0 api, here’s the code

@receiver(post_save, sender=OrgUser)
def user_is_created(sender, instance, created, **kwargs):
    if created:
        full_name = instance.full_name
        first_name = instance.first_name
        last_name = instance.last_name
        email = instance.email
        cell = instance.cell
        password = ''.join(random.choices(string.ascii_uppercase + string.digits, k=15))
        url = "https://127.0.0.1:8080/dbconnections/signup"
        user_data = {
            'client_id': config("APP_CLIENT_ID"),
            'connection': config("DATABASE_CONNECTION"),
            'full_name': full_name,
            'first_name': first_name,
            'last_name': last_name,
            'email': email,
            'password': password,     
            'cell': cell,
        }
        r = requests.post(url, json = user_data, headers = {'User-agent': 'your bot 0.1'}, verify=False)
    else:
        pass

I’m getting the following erroe message

requests.exceptions.SSLError: HTTPSConnectionPool(host='127.0.0.1', port=8080): Max retries exceeded with url: /dbconnections/signup (Caused by SSLError(SSLError(1, '[SSL: UNKNOWN_PROTOCOL] unknown protocol (_ssl.c:1091)')))

I searched for similar questiones but nothings helped so far.

I also have these two lines in the terminal after runnig the code

[07/Oct/2022 15:08:12] code 400, message Bad HTTP/0.9 request type ('x16x03x01x00Ýx01x00x00Ùx03x03}x9aPx98|9x9eÁ±XÀx97C)G@¶x880Gx80õx87u÷,'"µx96ü@x00x00bÀ0À,À/À+x00x9fx00x9eÀ2À.À1À-x00¥x00¡x00¤x00')
[07/Oct/2022 15:08:12] You're accessing the development server over HTTPS, but it only supports HTTP.

Answers:

This error can come about when an outdated version of pyOpenSSL exists within an environment. It may be worthwhile to to uninstall pyOpenSSL if the version is old and and reinstall reinstall a newer version.

Similar problem:
https://github.com/psf/requests/issues/4246

Answered By: Tanner

I fixed it. In my url I instead of

"https://127.0.0.1:8080/dbconnections/signup"

I had to put

"https://my-auth0-domain/dbconnections/signup"
Answered By: Mike D Hovhannisyan
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.