Open artem-yevtushenko-databricks opened 1 year ago
On my machine it works. Also by just following the link, for me it works.
Can you provide a bit more context about the error?
If this is this a request from a remote machine, like in my case in a GitHub Action, it's a known issue #30.
Hey I am running code from a GitHub codespace, brand new.
Installation:
pip install pysurfline
Python I am running:
import pysurfline
spot_id="5842041f4e65fad6a7708890"
forecasts = pysurfline.get_spot_forecasts(spot_id)
Error message:
/home/codespace/.python/current/lib/python3.10/site-packages/pysurfline/api.py:20: in get_spot_forecasts
return SurflineClient()._get_spot_forecasts(spotId)
/home/codespace/.python/current/lib/python3.10/site-packages/pysurfline/api.py:46: in _get_spot_forecasts
**APIResource(self, "spots/details")
/home/codespace/.python/current/lib/python3.10/site-packages/pysurfline/api.py:104: in get
raise e
/home/codespace/.python/current/lib/python3.10/site-packages/pysurfline/api.py:101: in get
self.response.raise_for_status()
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Response [403]>
def raise_for_status(self):
"""Raises :class:`HTTPError`, if one occurred."""
http_error_msg = ""
if isinstance(self.reason, bytes):
# We attempt to decode utf-8 first because some servers
# choose to localize their reason strings. If the string
# isn't utf-8, we fall back to iso-8859-1 for all other
# encodings. (See PR #3538)
try:
reason = self.reason.decode("utf-8")
except UnicodeDecodeError:
reason = self.reason.decode("iso-8859-1")
else:
reason = self.reason
if 400 <= self.status_code < 500:
http_error_msg = (
f"{self.status_code} Client Error: {reason} for url: {self.url}"
)
elif 500 <= self.status_code < 600:
http_error_msg = (
f"{self.status_code} Server Error: {reason} for url: {self.url}"
)
if http_error_msg:
> raise HTTPError(http_error_msg, response=self)
E requests.exceptions.HTTPError: 403 Client Error: Forbidden for url: https://services.surfline.com/kbyg/spots/details?spotId=5842041f4e65fad6a7708890
/home/codespace/.local/lib/python3.10/site-packages/requests/models.py:1021: HTTPError
If I try to just access manually the last url from error using my browser I get this:
URL: https://services.surfline.com/kbyg/spots/details?spotId=5842041f4e65fad6a7708890
webpage content: {"associated":{},"spot":{"name":"Pipeline"}}
I think that for some reason when running the code on remote machines it returns 403 Error.
I am planning to investigate but haven't found the time yet.
If you find a solution,I am happy to accept PRs!
@hiroferreira By doing a little research, it seems that the issue is due to the dynamic IP of codespaces and github actions (my use case where I encountered the same error).
A solution seems to be using a static IP.
As I don't use codespaces nor I have a GitHub Team account, could you give it a try and let me know? Would be really useful for addressing the error.
@giocaizzi i tried a hosted python on appengine and had the same error. Any other suggestions? Btw: my app reduced like 300MB when I removed your lib.
@hiroferreira Honestly I have no idea, but i want to investigate this further!
Regarding file size, how did you install it? Using pip or cloning the github repo? the package on PyPI is 10Kb, the dependencies are only three (requests, pandas,matplotlib) and they should not take that much space. The installed repository size would be much bigger, depending on fetch depth and branches. The main branch should be around 15Mb when compressed (as displayed on shields.io).
import pysurfline as sl sl.get_spot_forecasts("5842041f4e65fad6a7708890")
HTTPError: 403 Client Error: Forbidden for url: https://services.surfline.com/kbyg/spots/details?spotId=5842041f4e65fad6a7708890