bybit-exchange / pybit

Official Python3 API connector for Bybit's HTTP and WebSockets APIs.
Other
423 stars 135 forks source link

cannot import name 'HTTP' from 'pybit' #188

Closed BlackDCrypto closed 7 months ago

BlackDCrypto commented 10 months ago

Hello Hi, I'm trying to create a python code to connect to the bybit account and launch a bot, but I have this error

Si è verificata un'eccezione: ImportError cannot import name 'HTTP' from 'pybit' (C:\Users\Black\AppData\Local\Programs\Python\Python312\Lib\site-packages\pybit__init.py) File "C:\Users\Black\Documents\Python\Corteo.py", line 3, in from pybit import HTTP ImportError: cannot import name 'HTTP' from 'pybit' (C:\Users\Black\AppData\Local\Programs\Python\Python312\Lib\site-packages\pybit\init__.py)

pip install pybit ok pip install urllib3 ok pip install six ok

but don't work

Kamsby commented 10 months ago

Could you please refer the the sample code here - https://github.com/bybit-exchange/pybit/blob/master/examples/http_example_rsa_authentication.py

Which version of pybit you are using it ?

BlackDCrypto commented 10 months ago

Hi @Kamsby i'm using : Requirement already satisfied: pybit in c:\users\black\appdata\local\programs\python\python312\lib\site-packages (5.6.2) Requirement already satisfied: requests in c:\users\black\appdata\local\programs\python\python312\lib\site-packages (from pybit) (2.31.0) Requirement already satisfied: websocket-client in c:\users\black\appdata\local\programs\python\python312\lib\site-packages (from pybit) (1.7.0) Requirement already satisfied: websockets in c:\users\black\appdata\local\programs\python\python312\lib\site-packages (from pybit) (12.0) Requirement already satisfied: pycryptodome in c:\users\black\appdata\local\programs\python\python312\lib\site-packages (from pybit) (3.20.0) Requirement already satisfied: charset-normalizer<4,>=2 in c:\users\black\appdata\local\programs\python\python312\lib\site-packages (from requests->pybit) (3.3.2) Requirement already satisfied: idna<4,>=2.5 in c:\users\black\appdata\local\programs\python\python312\lib\site-packages (from requests->pybit) (3.6) Requirement already satisfied: urllib3<3,>=1.21.1 in c:\users\black\appdata\local\programs\python\python312\lib\site-packages (from requests->pybit) (1.24.2) Requirement already satisfied: certifi>=2017.4.17 in c:\users\black\appdata\local\programs\python\python312\lib\site-packages (from requests->pybit) (2023.11.17).

I tried to do a test with the recommended code but the error is always the same.

BlackDCrypto commented 10 months ago

i'm working to Visual Studio Code

Kamsby commented 10 months ago

Can you use the below. (refer the sample code given the example folder)

from pybit.unified_trading import HTTP

BlackDCrypto commented 9 months ago

Si è verificata un'eccezione: ModuleNotFoundError No module named 'urllib3.packages.six.moves' File "C:\Users\Black\Documents\Python\Corteo.py", line 1, in from pybit.unified_trading import HTTP ModuleNotFoundError: No module named 'urllib3.packages.six.moves'

dextertd commented 9 months ago

urllib3 is a dependency of requests, which is in pybit's requirements file: https://github.com/bybit-exchange/pybit/blob/master/requirements.txt

Can you create a new virtual environment and pip install pybit, and run the code again and let us know if you see the error?

olyamarch commented 9 months ago

Hi, I have similar issue.

I have just installed pybit: pip install pybit All was installed successfully.

Then I try to import the module: from pybit.unified_trading import HTTP But I get the error: TypeError: 'type' object is not subscriptable

Kamsby commented 9 months ago

@olyamarch Upgrade your python version to >=3.9

dextertd commented 9 months ago

@olyamarch That is a different issue #116

lac1995 commented 8 months ago

Same problem, cannot find pybit

QuantumCrazy commented 8 months ago

For Python version < 3.9:

import pybit
from pybit.unified_trading import HTTP

api_key = "XXX"
api_secret = "YYY"

session = HTTP(testnet=True,api_key=api_key,api_secret=api_secret)
print(session.get_coins_balance(accountType="FUND",coin="USDT"))

TypeError: 'type' object is not subscriptable

There is some error with the function HTTP with the v5 API.

For Python version >=3.9, same code above produces the error:

- pybit._http_manager - ERROR - invalid request, please check your server timestamp or recv_window param. req_timestamp[1711610220071],server_timestamp[1711610141518],recv_window[5000] (ErrCode: 10002). Added 2.5 seconds to recv_window. 2 retries remain.

Kamsby commented 7 months ago

- pybit._http_manager - ERROR - invalid request, please check your server timestamp or recv_window param. req_timestamp[1711610220071],server_timestamp[1711610141518],recv_window[5000] (ErrCode: 10002). Added 2.5 seconds to recv_window. 2 retries remain.

Sync your system/server time for this issue. (set time automatically from Date&Time)

muhd-k commented 6 months ago

I'm on python 3.11.0 and pybit 5.7.0. This is the error I'm getting:

Traceback (most recent call last): File "/Users/muhammad/Downloads/Crypto/bottt.py", line 2, in from pybit.unified_trading import HTTP File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pybit/unified_trading.py", line 7, in from ._v5_misc import MiscHTTP File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pybit/_v5_misc.py", line 1, in from ._http_manager import _V5HTTPManager File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pybit/_http_manager.py", line 6, in from Crypto.Hash import SHA256 ModuleNotFoundError: No module named 'Crypto'

xaldoxxx commented 6 months ago

pip install pycryptodome # solved ModuleNotFoundError: No module named 'Crypto'