Reputation: 721
I'm trying to play around with an API from Polygon and I'm getting this pretty long error
File "c:\Users\mitch\Desktop\stockmarket\app.py", line 12, in <module>
response = requests.get(url)
File "C:\Users\mitch\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\requests\api.py", line 75, in get
return request('get', url, params=params, **kwargs)
File "C:\Users\mitch\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\requests\api.py", line 61, in request
return session.request(method=method, url=url, **kwargs)
File "C:\Users\mitch\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\requests\sessions.py", line 529, in request
resp = self.send(prep, **send_kwargs)
File "C:\Users\mitch\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\requests\sessions.py", line 639, in send
adapter = self.get_adapter(url=request.url)
File "C:\Users\mitch\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\requests\sessions.py", line 732, in get_adapter
raise InvalidSchema("No connection adapters were found for {!r}".format(url))
requests.exceptions.InvalidSchema: No connection adapters were found for "{'https://api.polygon.io/v1/open-close/AAPL/2020-10-14?adjusted=true&apiKey={API_key}'}"
Here's my app code
import os
import requests
url = {
'https://api.polygon.io/v1/open-close/AAPL/2020-10-14?adjusted=true&apiKey={API_key}'
}
if os.path.isfile('.env'):
from dotenv import load_dotenv
load_dotenv()
response = requests.get(url)
if response.status_code == 200:
data = response.json()
print(data)
else:
print("error")
I'm passing the API key as a variable from a .env file. I even tried hard coding it into the url and it still got the same error response
Upvotes: 0
Views: 7013
Reputation: 40908
>>> url = {
... 'https://api.polygon.io/v1/open-close/AAPL/2020-10-14?adjusted=true&apiKey={API_key}'
... }
>>> type(url)
<class 'set'>
requests.get()
is expecting a str
, not a set
. Not certain what you were attempting to do here, but you wrapped your actual URL in a set
and did not actually format it with API_key
.
Upvotes: 3