[SOLVED]Error while import request package python 2.7.9

Hi,
I'm having trouble while import package requests in python

root@mylinkit:/IoT# python
imporPython 2.7.9 (default, Oct 26 2015, 17:43:12)
[GCC 4.8.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.                                                                                                  
>>> import requests
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/site-packages/requests/__init__.py", line 118, in <module>
    from . import utils
  File "/usr/lib/python2.7/site-packages/requests/utils.py", line 25, in <module>
    from . import certs
  File "/usr/lib/python2.7/site-packages/requests/certs.py", line 15, in <module>
    from certifi import where
  File "/usr/lib/python2.7/site-packages/certifi/__init__.py", line 1, in <module>
    from .core import contents, where
  File "/usr/lib/python2.7/site-packages/certifi/core.py", line 17
    def where() -> str:
                ^
SyntaxError: invalid syntax

I've already uninstall requests package and install again but it still occur this error.
Here is my information about OpenWrt OS and Python
Linux version 3.18.21 (buildbot@builder1) (gcc version 4.8.3 (OpenWrt/Linaro GCC 4.8-2014.04 r47269) ) #5 Fri Nov 20 12:43:14 CET 2015
Python 2.7.9 (default, Oct 26 2015, 17:43:12) [GCC 4.8.3] on linux2 Type "help", "copyright", "credits" or "license" for more information.
Could anyone suggest me how to fix this.

The issue is in the certifi-package, not requests.

Python 2.x has been deprecated for several years already.

1 Like

Yes sir, It has been deprecated but the problem is:
I have 50 modules, but only 5 pcs out of 50 have this issue. The rest still working fine.
And this python is built inside module MT7688 when I bought it from manufacturer, and code still working well with 45/50 pcs.

This forum is about official builds obtainable from downloads.openwrt.org or built yourself from the published source code. If you are using a manufacturer's custom built firmware, get support from them.

Python 2 is no longer built in the official builds. All Python applications should be migrated to Python 3.

1 Like

Then that means that the modules where your code isn't working have different versions of those Python-libraries than the rest, for whatever reason -- the whole firmware is probably a slightly different version.

You could try copying the Python-libraries from a working device. If that doesn't work, then you'll need to replace the firmware with the same version as on the working ones.

1 Like

Sorry, for not clear.
The python built-in the module is 2.7.9 but the all the package and opkg update is still from openwrt, right?

Could you share me the method to copy the python library to other devices. It may helpful

How would we know? The firmware your modules are running is customized by Seeed and therefore the servers it is downloading packages from can also be theirs. That's the whole point everyone has been telling you: you're not running OpenWrt, you're running Seeed's customized version of it and we do not know what they have and what they haven't modified.

If you want to know where it's downloading its packages from, look into /etc/opkg/distfeeds.conf

If you want to copy all the Python-libraries:

Format an SD-card or a USB-stick as ext4, then mount the card or stick on your working module. Then cp -a /usr/lib/python2.7 /path/to/your/card-or-stick/

Unmount the card/stick, move it to the other module, mount the card/stick there, then cp -a /path/to/your/card-or-stick/python2.7 /usr/lib/

Or if you just want to copy the certifi-library:

Format an SD-card or a USB-stick as ext4, then mount the card or stick on your working module. Then cp -a /usr/lib/python2.7/site-packages/certifi /path/to/your/card-or-stick/

Unmount the card/stick, move it to the other module, mount the card/stick there, then cp -a /path/to/your/card-or-stick/certifi /usr/lib/python2.7/site-packages/

1 Like

here is the file distfeeds.conf infor. It still use openWrt url
image

I guess, openWrt has some updates version in certifi and now it conflict with version of other packages

Thank you for your kind suggestion,
I have copy python library from working module to error module. And it worked.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.