Skip to content

Instantly share code, notes, and snippets.

@lupupaulsv
Created March 31, 2021 18:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lupupaulsv/2f13cdb432190111a05caa5c419b75bf to your computer and use it in GitHub Desktop.
Save lupupaulsv/2f13cdb432190111a05caa5c419b75bf to your computer and use it in GitHub Desktop.
>>> requests.get("https://api.nasdaq.com/api/quote/gme/option-chain/greeks?assetclass=stocks&date=2021-04-01", headers = {"Connection": "keep-alive","Accept-Encoding": "gzip, deflate, br","Accept": "*/*","User-Agent": "PostmanRuntime/7.26.8","Cache-Control": "no-cache","Scheme": "https","Host": "api.nasdaq.com","Filename": "/api/quote/gme/option-chain/greeks","Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8","Accept-Language": "en-US,en;q=0.5","Connection":"keep-alive","Cookie": "recentlyViewedList=GE|Stocks,TSLA|Stocks,API|Stocks,GME|Stocks","Upgrade-Insecure-Requests": "1"})
<Response [200]>
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
this works
>>> url = "https://api.nasdaq.com/api/quote/gme/option-chain/greeks?assetclass=stocks&date=2021-04-01"
>>> headers = {"Connection": "keep-alive","Accept-Encoding": "gzip, deflate, br","Accept": "*/*","User-Agent": "PostmanRuntime/7.26.8","Cache-Control": "no-cache","Scheme": "https","Host": "api.nasdaq.com","Filename": "/api/quote/gme/option-chain/greeks","Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8","Accept-Language": "en-US,en;q=0.5","Connection":"keep-alive","Cookie": "recentlyViewedList=GE|Stocks,TSLA|Stocks,API|Stocks,GME|Stocks","Upgrade-Insecure-Requests": "1"}
>>> requests.get(url, headers, timeout=5)
Traceback (most recent call last):
File "/var/www/option-sentiment/venv/lib/python3.7/site-packages/urllib3/connectionpool.py", line 445, in _make_request
six.raise_from(e, None)
File "<string>", line 3, in raise_from
File "/var/www/option-sentiment/venv/lib/python3.7/site-packages/urllib3/connectionpool.py", line 440, in _make_request
httplib_response = conn.getresponse()
File "/usr/lib/python3.7/http/client.py", line 1344, in getresponse
response.begin()
File "/usr/lib/python3.7/http/client.py", line 306, in begin
version, status, reason = self._read_status()
File "/usr/lib/python3.7/http/client.py", line 267, in _read_status
line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
File "/usr/lib/python3.7/socket.py", line 589, in readinto
return self._sock.recv_into(b)
File "/usr/lib/python3.7/ssl.py", line 1071, in recv_into
return self.read(nbytes, buffer)
File "/usr/lib/python3.7/ssl.py", line 929, in read
return self._sslobj.read(len, buffer)
socket.timeout: The read operation timed out
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/var/www/option-sentiment/venv/lib/python3.7/site-packages/requests/adapters.py", line 449, in send
timeout=timeout
File "/var/www/option-sentiment/venv/lib/python3.7/site-packages/urllib3/connectionpool.py", line 756, in urlopen
method, url, error=e, _pool=self, _stacktrace=sys.exc_info()[2]
File "/var/www/option-sentiment/venv/lib/python3.7/site-packages/urllib3/util/retry.py", line 532, in increment
raise six.reraise(type(error), error, _stacktrace)
File "/var/www/option-sentiment/venv/lib/python3.7/site-packages/urllib3/packages/six.py", line 735, in reraise
raise value
File "/var/www/option-sentiment/venv/lib/python3.7/site-packages/urllib3/connectionpool.py", line 706, in urlopen
chunked=chunked,
File "/var/www/option-sentiment/venv/lib/python3.7/site-packages/urllib3/connectionpool.py", line 447, in _make_request
self._raise_timeout(err=e, url=url, timeout_value=read_timeout)
File "/var/www/option-sentiment/venv/lib/python3.7/site-packages/urllib3/connectionpool.py", line 337, in _raise_timeout
self, url, "Read timed out. (read timeout=%s)" % timeout_value
urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='api.nasdaq.com', port=443): Read timed out. (read timeout=5)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/var/www/option-sentiment/venv/lib/python3.7/site-packages/requests/api.py", line 76, in get
return request('get', url, params=params, **kwargs)
File "/var/www/option-sentiment/venv/lib/python3.7/site-packages/requests/api.py", line 61, in request
return session.request(method=method, url=url, **kwargs)
File "/var/www/option-sentiment/venv/lib/python3.7/site-packages/requests/sessions.py", line 542, in request
resp = self.send(prep, **send_kwargs)
File "/var/www/option-sentiment/venv/lib/python3.7/site-packages/requests/sessions.py", line 655, in send
r = adapter.send(request, **kwargs)
File "/var/www/option-sentiment/venv/lib/python3.7/site-packages/requests/adapters.py", line 529, in send
raise ReadTimeout(e, request=request)
requests.exceptions.ReadTimeout: HTTPSConnectionPool(host='api.nasdaq.com', port=443): Read timed out. (read timeout=5)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
same code but in variables fails
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment