Anvil uplink SSL error

I’m getting the following error:

Python 3.12.2 (main, Feb  7 2024, 00:00:00) [GCC 13.2.1 20231205 (Red Hat 13.2.1-6)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import anvil.server
>>> anvil.server.connect("server_key")
Connecting to wss://anvil.works/uplink
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/user/src/anvil/venv/lib64/python3.12/site-packages/anvil/server.py", line 359, in connect
    _get_connection()
  File "/home/user/src/anvil/venv/lib64/python3.12/site-packages/anvil/server.py", line 341, in _get_connection
    raise e
  File "/home/user/src/anvil/venv/lib64/python3.12/site-packages/anvil/server.py", line 338, in _get_connection
    _connection.connect()
  File "/home/user/src/anvil/venv/lib64/python3.12/site-packages/ws4py/client/__init__.py", line 214, in connect
    self.sock = ssl.wrap_socket(self.sock, **self.ssl_options)
                ^^^^^^^^^^^^^^^
AttributeError: module 'ssl' has no attribute 'wrap_socket'
>>> 

I get the same error when running on Python 3.12 on Windows.

If I switch to Python 3.10 or 3.11 the uplink connects and works fine.

I have a small GUI program that used Python 3.12 and PyInstaller on Windows. I can’t get this GUI code to work in Python < 3.12 so I’m a bit stuck.

I’ve googled and I can see the ssl wrap_socket error is happening in some other Python packages with Python 3.12, but I’m not sure what I need to update/change to get things working.

Any tips on fixing this would be appreciated!

Welcome to the Forum!

I use Anvil Uplink regularly, but only up to Python 3.10, to avoid problems like this. As the very latest version of Python, I consider 3.12 to be somewhat “bleeding edge”. Clearly, Anvil Uplink 0.4.2 (the latest version on PyPI) hasn’t been vetted against it.

3.12 has removed wrap_socket:

The deprecation note suggests how one might code up a replacement. I don’t know how practical it might be to hack up your local copy of the Anvil Uplink package, to incorporate the suggested change.

No doubt Anvil is aware, and working on an update. But as an Anvil user, I have no idea what the schedule might be.

Thanks for the info.

I spent most of yesterday trying to update the code without much luck. I think the problem lies in the ws4py package used by anvil uplink.

I’ve now got my PySide6 code working in Python 3.10 so hopefully I can add anvil uplink without errors.

I’m new to open source and python in general. Reading 'Any package that still uses ssl.wrap_socket() is broken and insecure.’ in the link you provided is kinda worrying!

The python language itself has a slew of older features that are going to be either incorporated into consolidated parts of existing builtins, or given deprecated warnings for eventual removal in 3.13

Issues like this are going to become more frequent in the coming months/year, since some packages may need to be updated.

If a pypi package does not support the new version of python they should at least update the build information to reflect that the new version should not be installed with that version of python, but not all do.

In other words, if the package is being maintained and does not work with 3.12 they should release a new version that does not let you install it on 3.12 (and above) until they update their package code. Not everyone does this. Doing at least this would make your venv build fail and tell you exactly why.

See also coming in 3.13 PEP 594 is going live:

TLDR: lots of old library packages that used to be standard bog are being removed such as…

crypt
pipes
smtpd
telnetlib
and asynchat and asyncore (if you never updated to asyncio)
1 Like

So is the only*** solution to: “module ‘ssl’ has no attribute ‘wrap_socket’” for me to downgrade my Python version???

It’s not the only solution, just the supported one for right now. So if you can, yes.

If you can’t (because something you are trying to use with uplink is only supported by 3.12 or greater*) then there are probably unsupported workarounds that you could research (implementing an ssl import override for example is possible but not recommended.)
Or you can wait until anvil updates anvil-uplink.

This type of issue is always going to happen with the newest releases of any programming language, it is not specific to anvil, the anvil uplink, or python in general.

*You might try using a different version of the library you are trying to use that supports an earlier version of python, it is unlikely that one does not exist unless the library is just as new as the newest python. Look up your package on https://pypi.org/.

3 Likes

thanks! I solved by keeping all my existing code in my current Python 3.12 environment but put the Uplink on a different server environment with Python 3.10 which had access to the files from the first…

I just forked the ws4py library and updated it to be compatible with 3.12, I am about to post it in show and tell.

You might just have to include a different line for pip to install the forked version before having pip install anvil-uplink.

Stand by…

Here you go:

1 Like