Forum Archive

Pythonista 3 error on iPadOS: cannot connect to host discord.com:443 ssl=True

Penguin Master

I'm coding a Discord.py bot in python and I'm trying to move to pythonista but getting this error and i haven't found anyone else with this error on pythonista:

ssl.CertificateError: hostname 'IP-ADDRESS' doesn't match either of 'ssl764977.cloudflaressl.com', '*.discord.com', 'discord.com'

please help me with this as i spent $15 on this and would really like to be able to use it. Thank you!

JonB

@Penguin-Master said:

I'm coding a Discord.py bot in python and I'm trying to move to pythonista but getting this error and i haven't found anyone else with this error on pythonista:

ssl.CertificateError: hostname 'IP-ADDRESS' doesn't match either of 'ssl764977.cloudflaressl.com', '*.discord.com', 'discord.com'

please help me with this as i spent $15 on this and would really like to be able to use it. Thank you!

Looks like this is an issue with discord's certificate -- they are using an untrusted root certificate.

https://github.com/Rapptz/discord.py/issues/4159

On iOS, I believe you can down a cert offline, email it to yourself, and install as a trusted root.

Alternatively, you can disable SSL cert checks if you modify http.py :

async def get_from_cdn(self, url):
        async with self.__session.get(url) as resp:
 ```
Change to

async def get_from_cdn(self, url):
async with self.__session.get(url, ssl=False) as resp:
```

Dangerous, but I guess you are just risking trusting a fake discord server, it is not like you are sharing your bank info via discord.

There may be ways to go to discord.com in safari and down the certificate directly, but I'm not sure.

Penguin Master

@JonB thanks for the quick reply, I'll try that
Edit: didn't work. do you have any other ideas?

Penguin Master

OK, I looked at the issue you sent, and that's a different error. This one is hostname doesn't match, and the other one is certificate expired... 🤔

JonB

It is still a certificate error. -- did you try the change in http.py? You will need to force quit pythonista and try again

Penguin Master

@JonB yes I tried, but nothing happened

JonB

Can you post your full traceback?

Penguin Master

@JonB Sure

Penguin Master

@JonB here https://mystb.in/CasualSectionsDealt.rust

Unique_Name

Going back to version 1.5.0 fixed it for me, seems like pythonista just doesn’t like 1.5.1 for some reason

JonB

You could also try (before importing discord -- need to restart pythonista then try this)

import ssl
ssl.match_hostname = lambda cert, hostname: True

For some reason, ssl.match_hostname is being called with 'IP-ADDRESS' instead of an actual hostname. I'm not sure where that is coming from exactly, I guess the underlying _sslobj from OpenSSL. Pythonista uses an old OpenSSL version iirc, so this could explain it maybe.

Penguin Master

@JonB I can't thank you enough, I got Pythonista 3 mainly for this and now it works!!!