Python: Able to read rss url using chrome but unable to read using python

155 Views Asked by At
from datetime import datetime
import feedparser
import requests

def ESXi():
    NewsFeed = feedparser.parse("https://docs.vmware.com/en/VMware-vSphere/rn_rss.xml")
    print(NewsFeed)
    num = len(NewsFeed.entries)
{'bozo': 1, 'entries': [], 'feed': {'summary': '<h1>Access Denied</h1>\n \nYou don\'t have permission to access "http://docs.vmware.com/en/VMware-vSphere/rn_rss.xml" on this server.<p>\nReference #18.1c1d2017.1633578424.39d379a4'}, 'headers': {}, 'encoding': 'utf-8', 'version': '', 'bozo_exception': SAXParseException('mismatched tag'), 'namespaces': {}}

Able to check the rss feed using chrome but got this output while using python.

1

There are 1 best solutions below

0
Jesus Manuel Bustamante Sierra On

This happens because the agent is not authorized, you can use the following to change the agent just after all the imports:

feedparser.USER_AGENT = "Mozilla/5.0 (platform; rv:geckoversion) Gecko/geckotrail Firefox/firefoxversion"

After that you should not have any problems.