简体   繁体   中英

ValueError when using python venv

I'am currently trying to connect to my dropbox account using the API key in python. When i run it not using the virtual environment, I am able to get my profile information from the code below.

import dropbox

d = dropbox.Dropbox("myAPIkey")
    
print(d.users_get_current_account())

But when i run the code using my python venv, i get this error

Traceback (most recent call last):
  File "c:\users\user\appdata\local\programs\python\python38-32\lib\site-packages\urllib3\util\timeout.py", line 142, in _validate_timeout
    float(value)
TypeError: float() argument must be a string or a number, not 'Timeout'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
      File "d:/Desktop/FYP/FYP-TheBoyes/dropbox_tester.py", line 8, in <module>
        print(d.users_get_current_account())
      File "c:\users\user\appdata\local\programs\python\python38-32\lib\site-packages\dropbox\base.py", line 5216, in users_get_current_account
        r = self.request(
      File "c:\users\user\appdata\local\programs\python\python38-32\lib\site-packages\dropbox\dropbox_client.py", line 321, in request
        res = self.request_json_string_with_retry(host,
      File "c:\users\user\appdata\local\programs\python\python38-32\lib\site-packages\dropbox\dropbox_client.py", line 476, in request_json_string_with_retry
        return self.request_json_string(host,
      File "c:\users\user\appdata\local\programs\python\python38-32\lib\site-packages\dropbox\dropbox_client.py", line 588, in request_json_string
        r = self._session.post(url,
      File "d:\Desktop\FYP\FYP-Django\venv\lib\site-packages\requests\sessions.py", line 522, in post
        return self.request('POST', url, data=data, json=json, **kwargs)
      File "d:\Desktop\FYP\FYP-Django\venv\lib\site-packages\requests\sessions.py", line 475, in request
        resp = self.send(prep, **send_kwargs)
      File "d:\Desktop\FYP\FYP-Django\venv\lib\site-packages\requests\sessions.py", line 596, in send
        r = adapter.send(request, **kwargs)
      File "d:\Desktop\FYP\FYP-Django\venv\lib\site-packages\requests\adapters.py", line 413, in send
        resp = conn.urlopen(
      File "c:\users\user\appdata\local\programs\python\python38-32\lib\site-packages\urllib3\connectionpool.py", line 687, in urlopen
        timeout_obj = self._get_timeout(timeout)
      File "c:\users\user\appdata\local\programs\python\python38-32\lib\site-packages\urllib3\connectionpool.py", line 330, in _get_timeout
        return Timeout.from_float(timeout)
      File "c:\users\user\appdata\local\programs\python\python38-32\lib\site-packages\urllib3\util\timeout.py", line 179, in from_float
        return Timeout(read=timeout, connect=timeout)
      File "c:\users\user\appdata\local\programs\python\python38-32\lib\site-packages\urllib3\util\timeout.py", line 103, in __init__
        self._connect = self._validate_timeout(connect, "connect")
      File "c:\users\user\appdata\local\programs\python\python38-32\lib\site-packages\urllib3\util\timeout.py", line 144, in _validate_timeout
        raise ValueError(
    ValueError: Timeout value connect was Timeout(connect=100, read=100, total=None), but it must be an int, float or None.

Any way i can get this code to run in my python venv?

I suppose that you are running dropbox-sdk-python python package.
This kind of error seems to be related to the version of dependencies like explained in this thread .

So please be sure that all dependencies have the correct version based on requirements.txt file.

To check the version of all installed dependencies run the following command with the virtualenv activated.

pip freeze

Are you sure that you're using venv ?
If yes, then try running it without venv .
And keep your API in a seperate variable.
And try uninstalling Dropbox with pip uninstall dropbox and then install it by pip install dropbox .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM