BitMEX / api-connectors

Libraries for connecting to the BitMEX API.
https://www.bitmex.com/app/restAPI
909 stars 797 forks source link

'NoneType' object has no attribute 'setdefault' IN python module #270

Open sxp4u opened 5 years ago

sxp4u commented 5 years ago

Here is my code, just same as what's in README.md

import bitmex

client = bitmex.bitmex()
result = client.Quote.Quote_get(symbol="XBTUSD", reverse=True, count=1).result()

print(result[0][0]['bidSize'])

then it incur an exception message like this:

Traceback (most recent call last):
  File "/Users/shi/PycharmProjects/crypoarbitrage/bitmex_api.py", line 3, in <module>
    client = bitmex.bitmex()
  File "/Users/shi/anaconda/envs/unibook/lib/python3.6/site-packages/bitmex.py", line 38, in bitmex
    return SwaggerClient.from_url(spec_uri, config=config)
  File "/Users/shi/anaconda/envs/unibook/lib/python3.6/site-packages/bravado/client.py", line 96, in from_url
    spec_dict = loader.load_spec(spec_url)
  File "/Users/shi/anaconda/envs/unibook/lib/python3.6/site-packages/bravado/swagger_model.py", line 104, in load_spec
    self.request_headers,
  File "/Users/shi/anaconda/envs/unibook/lib/python3.6/site-packages/bravado/http_future.py", line 213, in result
    incoming_response = self._get_incoming_response(timeout)
  File "/Users/shi/anaconda/envs/unibook/lib/python3.6/site-packages/bravado/http_future.py", line 97, in wrapper
    return func(self, *args, **kwargs)
  File "/Users/shi/anaconda/envs/unibook/lib/python3.6/site-packages/bravado/http_future.py", line 228, in _get_incoming_response
    inner_response = self.future.result(timeout=timeout)
  File "/Users/shi/anaconda/envs/unibook/lib/python3.6/site-packages/bravado/requests_client.py", line 310, in result
    self.misc_options['ssl_cert'],
  File "/Users/shi/anaconda/envs/unibook/lib/python3.6/site-packages/requests/sessions.py", line 688, in merge_environment_settings
    proxies.setdefault(k, v)
AttributeError: 'NoneType' object has no attribute 'setdefault'

Do I config something wrong ? Is there anybody give me some hint ?

sxp4u commented 5 years ago

Actually, you can reproduce the issue using:

import bitmex

client = bitmex.bitmex()
# result = client.Quote.Quote_get(symbol="XBTUSD", reverse=True, count=1).result()

# print(result[0][0]['bidSize'])

the error message is the same:

Traceback (most recent call last):
  File "/Users/shi/PycharmProjects/crypoarbitrage/bitmex_api.py", line 3, in <module>
    client = bitmex.bitmex()
  File "/Users/shi/anaconda/envs/unibook/lib/python3.6/site-packages/bitmex.py", line 38, in bitmex
    return SwaggerClient.from_url(spec_uri, config=config)
  File "/Users/shi/anaconda/envs/unibook/lib/python3.6/site-packages/bravado/client.py", line 96, in from_url
    spec_dict = loader.load_spec(spec_url)
  File "/Users/shi/anaconda/envs/unibook/lib/python3.6/site-packages/bravado/swagger_model.py", line 104, in load_spec
    self.request_headers,
  File "/Users/shi/anaconda/envs/unibook/lib/python3.6/site-packages/bravado/http_future.py", line 213, in result
    incoming_response = self._get_incoming_response(timeout)
  File "/Users/shi/anaconda/envs/unibook/lib/python3.6/site-packages/bravado/http_future.py", line 97, in wrapper
    return func(self, *args, **kwargs)
  File "/Users/shi/anaconda/envs/unibook/lib/python3.6/site-packages/bravado/http_future.py", line 228, in _get_incoming_response
    inner_response = self.future.result(timeout=timeout)
  File "/Users/shi/anaconda/envs/unibook/lib/python3.6/site-packages/bravado/requests_client.py", line 310, in result
    self.misc_options['ssl_cert'],
  File "/Users/shi/anaconda/envs/unibook/lib/python3.6/site-packages/requests/sessions.py", line 688, in merge_environment_settings
    proxies.setdefault(k, v)
AttributeError: 'NoneType' object has no attribute 'setdefault'
sxp4u commented 5 years ago

I create a brand new Conda environment bitmex, enter it.
run pip install bitmex, still have this problem.

(bitmex) shi-MacBook-Pro:bitmex shi$ pip list 
Package                Version   
---------------------- ----------
bitmex                 0.2.2     
bravado                10.2.0    
bravado-core           5.0.7     
certifi                2018.10.15
chardet                3.0.4     
django-polls           0.1       
idna                   2.7       
jsonref                0.2       
jsonschema             2.6.0     
monotonic              1.5       
msgpack-python         0.5.6     
pip                    18.1      
python-dateutil        2.7.5     
pytz                   2018.7    
PyYAML                 3.13      
requests               2.20.0    
rfc3987                1.3.8     
setuptools             36.4.0    
simplejson             3.16.0    
six                    1.11.0    
strict-rfc3339         0.7       
swagger-client         1.0.0     
swagger-spec-validator 2.4.1     
urllib3                1.24      
webcolors              1.8.1     
wheel                  0.29.0    
(bitmex) shi-MacBook-Pro:bitmex shi$ ll
total 8
drwxr-xr-x  3 shixiaopeng  staff   96 11  2 17:38 .
drwxr-xr-x  8 shixiaopeng  staff  256 11  2 17:33 ..
-rw-r--r--  1 shixiaopeng  staff   42 11  2 17:38 demo.py
(bitmex) shi-MacBook-Pro:bitmex shi$ cat demo.py
import bitmex

client = bitmex.bitmex()

(bitmex) shi-MacBook-Pro:bitmex shi$ python demo.py 
Traceback (most recent call last):
  File "demo.py", line 3, in <module>
    client = bitmex.bitmex()
  File "/Users/shi/anaconda/envs/bitmex/lib/python3.6/site-packages/bitmex.py", line 38, in bitmex
    return SwaggerClient.from_url(spec_uri, config=config)
  File "/Users/shi/anaconda/envs/bitmex/lib/python3.6/site-packages/bravado/client.py", line 96, in from_url
    spec_dict = loader.load_spec(spec_url)
  File "/Users/shi/anaconda/envs/bitmex/lib/python3.6/site-packages/bravado/swagger_model.py", line 104, in load_spec
    self.request_headers,
  File "/Users/shi/anaconda/envs/bitmex/lib/python3.6/site-packages/bravado/http_future.py", line 213, in result
    incoming_response = self._get_incoming_response(timeout)
  File "/Users/shi/anaconda/envs/bitmex/lib/python3.6/site-packages/bravado/http_future.py", line 97, in wrapper
    return func(self, *args, **kwargs)
  File "/Users/shi/anaconda/envs/bitmex/lib/python3.6/site-packages/bravado/http_future.py", line 228, in _get_incoming_response
    inner_response = self.future.result(timeout=timeout)
  File "/Users/shi/anaconda/envs/bitmex/lib/python3.6/site-packages/bravado/requests_client.py", line 310, in result
    self.misc_options['ssl_cert'],
  File "/Users/shi/anaconda/envs/bitmex/lib/python3.6/site-packages/requests/sessions.py", line 693, in merge_environment_settings
    proxies.setdefault(k, v)
AttributeError: 'NoneType' object has no attribute 'setdefault'
(bitmex) shi-MacBook-Pro:bitmex shi$ 
Jrzg1992 commented 5 years ago

Have you solved the problem?I have the same problem.

sxp4u commented 5 years ago

This problem is associated with proxies. When I open Lantern, this problem appear, and when I close Lantern this problem disappear.

sxp4u commented 5 years ago

Have you solved the problem?I have the same problem.

I solve this problem by Quiting Lantern, and using OpenVPN build on my cloud server.

sxp4u commented 5 years ago

Also, this may be helpful @wyxr https://github.com/Yelp/bravado/issues/361

Fzkbnb commented 5 years ago

Have you solved the problem?I have the same problem.

me too

LourensVeen commented 5 years ago

This seems to be a Bravado issue, see https://github.com/Yelp/bravado/issues/401. You could try downgrading to Bravado 10.1.0, that worked for me.