danielmichaels / fuelwatcher

A simple XML scraper for fuelwatch.wa.gov.au fuel price data.
MIT License
5 stars 4 forks source link

api.query() returning empty variable #34

Closed giovannifi closed 2 years ago

giovannifi commented 2 years ago

Every time I run the command:

api.query(day='yesterday', brand=20, product=1)

it returns an empty variable (None). I also tried the command reported on the PiPy webpage (https://pypi.org/project/fuelwatcher/):

api.query(product=2, region=25, day='yesterday')

and again I got an empty value (returns None)

is this the correct behaviour?

I suspect that the format of the FuelWatch XML RSS changed and therefore the api is not able to grab the info anymore.

giovannifi commented 2 years ago

I think the problem is that FuelWatch changed the permissions for the RSS page http://fuelwatch.wa.gov.au/fuelwatch/fuelWatchRSS

I tried to run the following code:

import requests
url = 'http://fuelwatch.wa.gov.au/fuelwatch/fuelWatchRSS?'
response = requests.get(url)
print(response)

and I get "Response [403] - forbidden". This indicates that the server understand the request but it does not authorise it. This must be the reason why fuelwatcher is returning an empty variable.

danielmichaels commented 2 years ago

Thanks for raising this issue.

I conducted some quick testing and am pretty confident that the Fuel Watcher server is just scanning for user agent strings and denying requests based on that.

To test this yourself try:

import requests
url = 'http://fuelwatch.wa.gov.au/fuelwatch/fuelWatchRSS?'
response = requests.get(url, headers={"User-Agent": "googlebot"}) # anything but the default python/requests
print(response)

I am working on a more persistent and reliable fix. In the short term please checkout the #35 pull request.

danielmichaels commented 2 years ago

@giovannifi please try the latest version of fuelwatcher.

You can ensure the most recent version is installed by pinning the package.

# requirements.txt
fuelwatcher==0.2.3
# or in a shell
pip install fuelwatcher==0.2.3
giovannifi commented 2 years ago

thanks. By mistake I run the command

pip install fuelwatcher --upgrade

and this installed the version 0.2.21. I tested it and it seems to work now.

danielmichaels commented 2 years ago

Glad to hear its working. 👌