Forums

Python feedparser works locally but returns 403 on pythonanywhere

Hello everybody,

could you please help me figuring out, why the following feedparser code works locally (I get the feed with 20 entries) but fails when the same script is executed on pythonanywhere (full error message below)?

feed = feedparser.parse(f"https://www.feed_url.rss", agent='XYZ/3.0')

I have purchased a Hacker subscription, tried different agents, and updated feedparser. On my local machine, I'm using a miniconda environment and on pythonanywhere I'm just using the preinstalled python packages. The versions are different. Might that be the reason?

Any idea on how to fix this issue?

Thank you very much in advance! Best regards Key

Here is what I get when printing the feed object:

{'bozo': 1, 'entries': [], 'feed': {'summary': '<h1>Access Denied</h1>\n \nYou don\'t have permission to access "http://www.feed_url.rss" on this server.<p>\nReference #18.8f2a0660.1656365549.9fe5689'}, 'headers': {'mime-version': '1.0', 'content-type': 'text/html', 'content-length': '313', 'cache-control': 'max-age=0', 'date': 'Mon, 27 Jun 2022 21:32:29 GMT', 'connection': 'close', 'server-timing': 'edge; dur=1'}, 'href': 'https://www.feed_url.rss', 'status': 403, 'encoding': 'us-ascii', 'bozo_exception': SAXParseException('mismatched tag'), 'version': '', 'namespaces': {}}

That error is coming from the service you're trying to access, so you will need to check the authentication that is necessary to access that URL. It may also be that that server is blocking access from particular URLs or geographical locations - that's something that you'll need to check with the people that run the site.