jasonacox / tinytuya

Python API for Tuya WiFi smart devices using a direct local area network (LAN) connection or the cloud (TuyaCloud API).
MIT License
879 stars 159 forks source link

Tinytuya unable to import due to outdated openSSL #377

Open Frefdt opened 1 year ago

Frefdt commented 1 year ago

image

jasonacox commented 1 year ago

ImportError: urllib3 v2.0 only supports OpenSSL 1.1.1+, currently the "ssl’ module is compiled with ‘OpenSSL 1.1.0h 27 Mar 2018". See: https://github.com/urllib3/urllib3/issues/2168

TinyTuya uses the requests library which uses urllib3. It seems that v2 of urllib3 now requires OpenSSL 1.1.1 but your python environment has OpenSSL 1.1.0.

Workaround:

# remove urllib3 v2
pip uninstall urllib3

# install older version that support openssl v1.1.0
pip install urllib3==1.26.5 

I need to research if there is a good way we can address this. Since urllib3's decision to remove support for OpenSSL < 1.1.1, many other projects are impacted due to the transitive dependencies in python modules.

Any suggestions or PRs appreciated. 😁

uzlonewolf commented 1 year ago

While it won't fix it, perhaps we should wrap that import in a try/except and print a message if it fails. That would at least allow local control to keep working.

jasonacox commented 1 year ago

Ooooh! That's a great idea. I wonder if this would work...

try:
    import requests
except ImportError as impErr:
    print("WARN: Unable to import requests library, Cloud functions will not work.")
    print("WARN: Check dependencies. See https://github.com/jasonacox/tinytuya/issues/377")
    print("WARN: Error: {}.".format(impErr.args[0]))

@Frefdt can you try this (just paste into a python prompt)? Also, what OS are you using?

Frefdt commented 1 year ago

image Yeah, seems like it works! Currently running windows 10, but being that this was a fresh install of both python 3.7 and vscode its probably for the best if you wrap it in there for others that encounter similar problems

Frefdt commented 1 year ago

Also workaround worked just fine, thank you for the quick responses :)

jasonacox commented 1 year ago

Thanks @Frefdt !

@uzlonewolf I thought about folding this into #370 but don't want to conflate it - I think we make this a minor patch (v1.12.9).

Frefdt commented 1 year ago

Sounds like the best idea- just tested on a fresh vm and had the same issue so don't think it's an issue with my config specifically