stjet / bananopie

A python library for Banano. Not just a RPC wrapper!
https://pypi.org/project/bananopie/
MIT License
16 stars 2 forks source link

Error when running examples: "cannot import name 'Mapping' from 'collections'" #1

Closed jrentsch closed 1 year ago

jrentsch commented 1 year ago

Using the first example:

`from bananopie import *

rpc = RPC("https://kaliumapi.appditto.com/api")`

Yields the following:

`--------------------------------------------------------------------------- ImportError Traceback (most recent call last) Cell In[5], line 1 ----> 1 from bananopie import * 2 rpc = RPC("https://kaliumapi.appditto.com/api")

File /opt/conda/lib/python3.11/site-packages/bananopie/init.py:1 ----> 1 from .rpc import RPC 2 from .wallet import Wallet 3 from .util import *

File /opt/conda/lib/python3.11/site-packages/bananopie/rpc.py:1 ----> 1 import requests 3 class RPC: 4 def init(self, rpc_url: str, auth = False, legacy = False):

File /opt/conda/lib/python3.11/site-packages/requests/init.py:43 6 """ 7 Requests HTTP Library 8 ~~~~~ (...) 38 :license: Apache 2.0, see LICENSE for more details. 39 """ 41 import warnings ---> 43 import urllib3 45 from .exceptions import RequestsDependencyWarning 47 try:

File /opt/conda/lib/python3.11/site-packages/urllib3/init.py:8 5 from future import absolute_import 6 import warnings ----> 8 from .connectionpool import ( 9 HTTPConnectionPool, 10 HTTPSConnectionPool, 11 connection_from_url 12 ) 14 from . import exceptions 15 from .filepost import encode_multipart_formdata

File /opt/conda/lib/python3.11/site-packages/urllib3/connectionpool.py:29 27 from .packages import six 28 from .packages.six.moves import queue ---> 29 from .connection import ( 30 port_by_scheme, 31 DummyConnection, 32 HTTPConnection, HTTPSConnection, VerifiedHTTPSConnection, 33 HTTPException, BaseSSLError, 34 ) 35 from .request import RequestMethods 36 from .response import HTTPResponse

File /opt/conda/lib/python3.11/site-packages/urllib3/connection.py:39 31 from .exceptions import ( 32 NewConnectionError, 33 ConnectTimeoutError, 34 SubjectAltNameWarning, 35 SystemTimeWarning, 36 ) 37 from .packages.ssl_match_hostname import matchhostname, CertificateError ---> 39 from .util.ssl import ( 40 resolve_cert_reqs, 41 resolve_ssl_version, 42 assert_fingerprint, 43 create_urllib3_context, 44 ssl_wrap_socket 45 ) 48 from .util import connection 50 from ._collections import HTTPHeaderDict

File /opt/conda/lib/python3.11/site-packages/urllib3/util/init.py:3 1 from future import absolute_import 2 # For backwards compatibility, provide imports that used to be here. ----> 3 from .connection import is_connection_dropped 4 from .request import make_headers 5 from .response import is_fp_closed

File /opt/conda/lib/python3.11/site-packages/urllib3/util/connection.py:3 1 from future import absolute_import 2 import socket ----> 3 from .wait import wait_for_read 4 from .selectors import HAS_SELECT, SelectorError 7 def is_connection_dropped(conn): # Platform-specific

File /opt/conda/lib/python3.11/site-packages/urllib3/util/wait.py:1 ----> 1 from .selectors import ( 2 HAS_SELECT, 3 DefaultSelector, 4 EVENT_READ, 5 EVENT_WRITE 6 ) 9 def _wait_for_io_events(socks, events, timeout=None): 10 """ Waits for IO events to be available from a list of sockets 11 or optionally a single socket if passed in. Returns a list of 12 sockets that can be interacted with immediately. """

File /opt/conda/lib/python3.11/site-packages/urllib3/util/selectors.py:14 12 import sys 13 import time ---> 14 from collections import namedtuple, Mapping 16 try: 17 monotonic = time.monotonic

ImportError: cannot import name 'Mapping' from 'collections' (/opt/conda/lib/python3.11/collections/init.py)`

Using:

stjet commented 1 year ago

Hmm, thanks for the report. Looks like some dependency thing - I'll take a look.

stjet commented 1 year ago

@jrentsch I think you need to update urllib3, which is a dependency of requests, which is a dependency of this library: https://stackoverflow.com/questions/71632325/cannot-import-name-mapping-from-collections-on-importing-requests

pip install urllib3 --upgrade

stjet commented 1 year ago

Let me know if that doesn't fix it, but I think it should. On my end I don't have any min version for "requests" specified, so my hypothesis if you already installed requests or urllib3 before, but an older version, that doesn't work after python 3.10. Bananopie has requests (and therefore urllib3) as dependencies, but doesn't have any version requirements for them, so the system just uses the old version (?).