Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cannot import name 'encode_single' from 'eth_abi' #12

Closed
abradshaw opened this issue Jan 8, 2024 · 4 comments
Closed

cannot import name 'encode_single' from 'eth_abi' #12

abradshaw opened this issue Jan 8, 2024 · 4 comments

Comments

@abradshaw
Copy link

When trying to run python3 satochip_bridge/SatochipBridge.py I get the following (the requirements all installed ok)

$ python3 satochip_bridge/SatochipBridge.py
Traceback (most recent call last):
  File "/home/fab/abradsha/Nextcloud/Copy/git/Satochip-Bridge/satochip_bridge/SatochipBridge.py", line 10, in <module>
    from py_eth_sig_utils import eip712
  File "/home/fab/abradsha/.local/lib/python3.12/site-packages/py_eth_sig_utils/__init__.py", line 3, in <module>
    from . import (  # NOQA
  File "/home/fab/abradsha/.local/lib/python3.12/site-packages/py_eth_sig_utils/signing.py", line 3, in <module>
    from .eip712 import encode_typed_data
  File "/home/fab/abradsha/.local/lib/python3.12/site-packages/py_eth_sig_utils/eip712/__init__.py", line 3, in <module>
    from .encoding import (  # NOQA
  File "/home/fab/abradsha/.local/lib/python3.12/site-packages/py_eth_sig_utils/eip712/encoding.py", line 2, in <module>
    from eth_abi import encode_single, encode_abi
ImportError: cannot import name 'encode_single' from 'eth_abi' (/home/fab/abradsha/.local/lib/python3.12/site-packages/eth_abi/__init__.py)

@abradshaw
Copy link
Author

My OS is Fedora, however I have also just installed an Ubuntu machine to test with - same error

Probably related to ethereum/web3.py#2621

@abradshaw
Copy link
Author

abradshaw commented Jan 14, 2024

I did some work getting this to run natively (no appimage) in a modern Linux system (Fedora 39).

To start with you will need python 3.11 (and Fedora39 ships with 3.12, so you will need to do this all from a venv

Before you start, ensure you have the python development package installed

sudo dnf install python3.11 python3.11-devel
python3.11 -m venv venv-3.11
source venv-3.11/bin/activate

From within this venv you need to pull in all the requirements. (note: the documentation is wrong here until this MR is merged #4)

(venv-3.11) username@laptop:~/git/Satochip-Bridge$ python3 -m pip install -r contrib/requirements/requirements.txt

If you get any messages like Failed building wheel for pyscard then pip install wheel

Once the requirements are done, you still have 2 things to do

  1. you need to downgrade the pip package for eth_abi or you will get errors about encode_single. Weirdly you need to use the upgrade syntax to downgrade from 5.0.0 to 3.0.0
(venv-3.11) username@laptop:~/git/Satochip-Bridge$ pip3 install --upgrade eth_abi==3.0.0 
  1. you will now only get one error - cannot import name 'getargspec' see Python 3.11 ImportError: cannot import name 'getargspec' from 'inspect' ethereum/web3.py#2704

First, from within your 3.11 venv, make sure you have the pip module parsimonious

(venv-3.11) username@laptop:~/git/Satochip-Bridge$ pip3 install parsimonious

Finally you will need to edit a file in your site-packages dir ....

(venv-3.11) user@-laptop:~/git/Satochip-Bridge$ nvim ./venv-3.11/lib64/python3.11/site-packages/parsimonious/expressions.py

Change the import line from getargspec to getfullargspec (I commented the old line and added a new one)

from inspect import getfullargspec
# from inspect import getargspec

Now everything should work

PS: I still get smartcard.Exceptions.CardConnectionException: Unable to connect with protocol: T0 or T1. Card is unpowered. when I remove a card, the same as in the .appimage

@abradshaw
Copy link
Author

As I mentioned in my previous comment I was getting

Traceback (most recent call last):
  File "/home/fab/abradsha/Nextcloud/Copy/git/Satochip-Bridge/venv-3.11/lib64/python3.11/site-packages/smartcard/CardMonitoring.py", line 179, in run
    self.observable.notifyObservers(
  File "/home/fab/abradsha/Nextcloud/Copy/git/Satochip-Bridge/venv-3.11/lib64/python3.11/site-packages/smartcard/Observer.py", line 62, in notifyObservers
    observer.update(self, arg)
  File "/home/fab/abradsha/Nextcloud/Copy/git/Satochip-Bridge/venv-3.11/lib64/python3.11/site-packages/pysatochip/CardConnector.py", line 99, in update
    self.cc.cardservice.connection.connect()
  File "/home/fab/abradsha/Nextcloud/Copy/git/Satochip-Bridge/venv-3.11/lib64/python3.11/site-packages/smartcard/CardConnectionDecorator.py", line 54, in connect
    self.component.connect(protocol, mode, disposition)
  File "/home/fab/abradsha/Nextcloud/Copy/git/Satochip-Bridge/venv-3.11/lib64/python3.11/site-packages/smartcard/pcsc/PCSCCardConnection.py", line 123, in connect
    raise CardConnectionException(
smartcard.Exceptions.CardConnectionException: Unable to connect with protocol: T0 or T1. Card protocol mismatch.

When removing the card or when connecting the reader without the card entered. I also get this same message now I have the packages installed locally in my Fedora 39

On a hunch I tried to recreate the issue using a different reader - a Identiv SCR 3310 v2.0 - SCM USB SmartCard Reader - this works Perfectly

So in summary, the reader that SatoChip ship seems to have an issue when removing/re-inserting the card when running on a Linux OS - changing the reader to a SCR 3310 solves the issue and cards can be removed and re-inserted again and again with now Tracebacks.

So it looks like an issue with the current Linux driver for SatoChip Reader (Alcor Micro Corp. AU9540 Smartcard Reader)

I would be happy to close this ticket as it seems to be an upstream issue

@Toporin
Copy link
Owner

Toporin commented Jan 17, 2024

Thanks for the detailed feedback!
Note that w are reorganizing our tools and we may restructure Satochip-Bridge in the near future.
Satochip has been integrated natively in Uniblow (https://uniblow.org/) which provides similar functionalities (web3 connection with WalletConnect support) and supports more blockchains (Eth, Doge, Tezos, ...).
So we may release a version of Satochip-Bridge that focus on the card management (seed import/reset, enable/disable 2FA, reset factory...)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants