Open haydencall opened 3 years ago
Looks like it's pinned to 0.4.13
in requirements.txt.
To use the latest version, I think this line here: https://github.com/barnumbirr/coinmarketcap/blob/2b951be7cedd7efc484f50f27600ee8a003f3c94/coinmarketcap/core.py#L27
Just needs to reference requests_cache.CachedSession
instead of requests_cache.core.CachedSession
.
Same error, what is the solution for this? I executed that line but gave other error:
>>> self._session = requests_cache.core.CachedSession(cache_name=self.cache_name, backend='sqlite', expire_after=120)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'requests_cache' is not defined
That looks like a different error, probably just missing dependencies. Try:
pip install requests-cache==0.5.2
No Need. I managed to make it work this morning:
from requests import Request, Session
from requests.exceptions import ConnectionError, Timeout, TooManyRedirects
import json
import pprint
import os
pp = pprint.PrettyPrinter(indent=4)
key = yourAPIkey
url = f'https://pro-api.coinmarketcap.com/v1/cryptocurrency/quotes/latest'
print(url)
headers = {
'Accepts': 'application/json',
'X-CMC_PRO_API_KEY': key,
}
parameters = {
'symbol':'BTC,ETH'
}
session = Session()
session.headers.update(headers)
try:
response = session.get(url, params=parameters)
data = json.loads(response.text)
btcPrice = data["data"]["BTC"]["quote"]["USD"]["price"]
pp.pprint(btcPrice)
except (ConnectionError, Timeout, TooManyRedirects) as e:
data = json.loads(response.text)
pp.pprint(data)
@tifDev This works for me, Thanks!
The request sent doesn't have the attribute 'core' Has anyone else had this issue? What version of requests should I have imported to use this library?