Forums

AttributeError: module 'socks' has no attribute 'HTTP'

my error log is at: https://www.pythonanywhere.com/user/rabinniroula/files/var/log/rabinniroula.pythonanywhere.com.error.log

It says: AttributeError: module 'socks' has no attribute 'HTTP'. can anybody please help me solve it.

I wonder if that's a version issue

how can I solve it?

what version of socks you are using? (and what version of python etc)

I have the same error but I don't use socks

certainly sounds like some library you are using is using socks behind the scenes.

I have the same error using paho-mqtt installed in python3.8 with pip3.8 the code runs on a PC with idle without error. Any idea?

.local/lib/python3.8/site-packages/paho/mqtt/client.py", line 3480, in check t in set([socks.HTTP, socks.SOCKS4, socks.SOCKS5]) and a) AttributeError: module 'socks' has no attribute 'HTTP'

Could you try running this command in Bash and see if it fixes the problem?

pip3.8 install --user --force-reinstall PySocks

@helixiot, that command should work for you without modification, as you're using Python 3.8.

@rabinniroula, @Apoloing -- you may need to replace the "3.8" in the command with the version of Python that your code is using.

I did a brute force fix on this. I created a virtual environment and tried 3.8 there with the package, no luck, same error. Deleted the virtual environment and created another with 3.6 with the package, guess what this worked fine. I tried pointing my web app at that path and got a wrong python version error.

I downgraded the account to free, opened a new account, set up the web app as 3.6 instead of 3.8. Created a 3.6 virtual environment, added the package into the virtual environment only, again this worked fine.

Something to do with 3.8.

Will I automatically get a refund on the downgraded account, I only paid for it a day ago? Put through the payment on the 2nd account today to get the MQTT working so don't want to pay for both.

Interesting! Yes, it sounds like the library that you're using is not compatible with Python 3.8, but it's not publishing that fact on PyPI, so pip will happily install it despite the incompatibility.

The refund is something we have to kick off from our side -- I've done that just now, and it should be back in your account within ten working days (normally much less time, but it does depend on how long your bank takes to process it).

So the only thing is that the package does work with 3.8 on a Win10 PC and Linux Raspberry Pi, just not on Pythonanywhere.

I never did try the forced upgrade you discussed. If someone there can confirm the path to getting it to work on 3.8 I would ultimately like to upgrade to that. I can use 3.6 on the new account I mentioned earlier in the mean time.

Hi @helixiot -- could you share relevant bit of code that you're using, so we could try to reproduce that?

[formatted by admin]

import paho.mqtt.client as mqtt
import time

def on_message(client, userdata, message):
    print("received message: " ,str(message.payload.decode("utf-8")))

    mqttBroker ="broker.hivemq.com"

    client = mqtt.Client("")
    client.connect(mqttBroker)

    client.loop_start()

    client.subscribe("a_topic/example")
    client.on_message=on_message

    time.sleep(30)
    client.loop_stop()

Thanks! Given that the code runs with Python 3.8 on your Raspberry Pi and Windows machine -- could you do pip freeze on both machines in your working environments for Python 3.8 and share that with us? Maybe there is some mismatch in versions for Python 3.8 on PythonAnywhere for relevant modules which causes the issue...

Hi is there any progress on this I got the same issue, I just upgraded my account to be able to connect with MQTT broker after I got the connection refused, and now cant module 'socks' has no attribute 'HTTP'? (my version python 3.7)

Does it work in 3.6? Do you have it working locally with 3.8? If you do, compare the pip freeze output between your local machine and PythonAnywhere. Perhaps there's a clue there.

@glenn don't know if it works in 3.6 or 3.8, by reading the above version doesn't help, there is nothing specific in packages I use and are exactly the same here and on my computer: click==7.1.2 Flask==1.1.2 itsdangerous==1.1.0 Jinja2==2.11.3 MarkupSafe==1.1.1 paho-mqtt==1.5.1 Werkzeug==1.0.1

anyway, I tried with digitalocean and it works.

In the posts above, @helixiot found that it did work with Python 3.6, but didn't with Python 3.8, which is why @glenn was asking about that. Which version of Python are you using on PythonAnywhere?