Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update rssfdw.py #230

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions python/multicorn/rssfdw.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,13 @@
from datetime import datetime, timedelta
from lxml import etree
try:
from urllib.request import urlopen
from urllib.request import urlopen, Request
except ImportError:
from urllib import urlopen
from urllib import urlopen, Request
from logging import ERROR, WARNING
from multicorn.utils import log_to_postgres
import json

import ssl

def element_to_dict(element):
"""
Expand Down Expand Up @@ -140,7 +140,7 @@ def __init__(self, options, columns):
self.columns = columns
self.default_namespace_prefix = options.pop(
'default_namespace_prefix', None)
self.item_root = options.pop('item_root', 'item')
self.item_root = options.pop('item_root', 'entry')

def get_namespaces(self, xml):
ns = dict(xml.nsmap)
Expand Down Expand Up @@ -175,7 +175,14 @@ def execute(self, quals, columns):
if (datetime.now() - date) < self.cache_duration:
return values
try:
xml = etree.fromstring(urlopen(self.url).read())
ssl._create_default_https_context = ssl._create_unverified_context
req = Request(
url = self.url,
data=None,
headers={'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.47 Safari/537.36'}
)
s = urlopen(req).read()
xml = etree.fromstring(s)
items = [self.make_item_from_xml(elem)
for elem in xml.xpath(
'//%s' % self.item_root,
Expand Down