Skip to content
This repository has been archived by the owner on Aug 26, 2023. It is now read-only.

AttributeError: module 'requests_cache' has no attribute 'core' #58

Open
haydencall opened this issue May 20, 2021 · 5 comments
Open

AttributeError: module 'requests_cache' has no attribute 'core' #58

haydencall opened this issue May 20, 2021 · 5 comments

Comments

@haydencall
Copy link

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?

@JWCook
Copy link

JWCook commented May 20, 2021

Looks like it's pinned to 0.4.13 in requirements.txt.

To use the latest version, I think this line here:

self._session = requests_cache.core.CachedSession(cache_name=self.cache_name, backend='sqlite', expire_after=120)

Just needs to reference requests_cache.CachedSession instead of requests_cache.core.CachedSession.

@tifDev
Copy link

tifDev commented Jun 15, 2021

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

@JWCook
Copy link

JWCook commented Jun 16, 2021

That looks like a different error, probably just missing dependencies. Try:

pip install requests-cache==0.5.2

@tifDev
Copy link

tifDev commented Jun 16, 2021

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)

@aoki-h-jp
Copy link

@tifDev This works for me, Thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants