Skip to content

Commit 4da2a1e

Browse files
committed
FIX #718 - Windows - RSS iDevice
1 parent 5531399 commit 4da2a1e

File tree

1 file changed

+23
-6
lines changed

1 file changed

+23
-6
lines changed

exe/engine/rssidevice.py

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,22 @@
2525
import re
2626
import requests
2727
import feedparser
28+
import urllib
29+
import ssl
30+
from sys import platform
2831

2932
from exe.engine.idevice import Idevice
3033
from exe.engine.field import TextAreaField
3134
from exe.engine.translate import lateTranslate
3235

3336

37+
class UrlOpener(urllib.FancyURLopener):
38+
"""
39+
Set a distinctive User-Agent, so Wikipedia.org knows we're not spammers
40+
"""
41+
version = "eXe/[email protected]"
42+
urllib._urlopener = UrlOpener()
43+
3444
# ===========================================================================
3545
class RssIdevice(Idevice):
3646
"""
@@ -100,10 +110,15 @@ def loadRss(self, url):
100110
try:
101111
rssDic = []
102112
headers={'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:50.0) Gecko/20100101 Firefox/50.0'}
103-
response = requests.get(url, timeout=10, headers=headers)
104-
statuscode = response.status_code
105-
if statuscode == 200:
106-
rssDic = feedparser.parse(response.text)
113+
#response = requests.get(url, timeout=10, headers=headers, verify='cacert.pem')
114+
if (platform == 'darwin' and hasattr(sys, 'frozen')):
115+
response = urllib.urlopen(url, context=ssl.create_default_context(cafile='cacert.pem'))
116+
if platform == 'darwin':
117+
response = urllib.urlopen(url, context=ssl.create_default_context(cafile='cacert.pem'))
118+
else:
119+
response = urllib.urlopen(url)
120+
#rssDic = feedparser.parse(response.text)
121+
rssDic = feedparser.parse(response.read())
107122
length = len(rssDic['entries'])
108123
if length > 0 :
109124
content += "<ul>"
@@ -112,8 +127,10 @@ def loadRss(self, url):
112127
rssDic['entries'][i].link, rssDic['entries'][i].title)
113128
content += "</ul>"
114129
except Exception, error:
115-
log.error(unicode(error))
116-
content += _(u"Unable to load RSS feed from %s <br/>Please check the spelling and connection and try again.") % url
130+
content += _(u"Unable to load RSS feed from %s <br/>Please check the spelling and connection and try again. ") % url
131+
content += _(u"Error: %s") % unicode(error)
132+
# import traceback
133+
# content += _(u"Traceback: %s") % unicode(traceback.format_exc())
117134

118135
if content == "":
119136
content += _(u"Unable to load RSS feed from %s <br/>Please check the spelling and connection and try again.") % url

0 commit comments

Comments
 (0)