I hadn't time to pursue the cookielib road and managed the following (too) simple hack in Util.py:
@staticmethod
def urlopen(url, data=None, head_request=False):
if url.startswith('//'):
url = 'http:' + url
request = urllib2.Request(url) if not head_request else HeadRequest(url) request.add_header('User-Agent', USER_AGENT) request.add_header('Cache-Control', 'max-age=0')
# session cookies for wallhaven
cookiefile = '~/.config/variety/cookies/cookies.txt'
if url.find('wallhaven')>0 and os.path.exists(cookiefile):
cookies = ''
with open(cookiefile) as CF:
for line in CF: _, _, _, _, name, value = line.strip().split('\t') cookies += "%s=%s;" % (name,value) request.add_header('Cookie', cookies )
return urllib2.urlopen(request, data=urllib.urlencode(data) if data else None, timeout=20)
Once Util.py is "fixed" as above, to enable session cookies for wallhaven you just log-on with Firefox to wallhaven and save the session cookies to ~/.config/variety/cookies/cookies.txt by using the Firebug extension
I hadn't time to pursue the cookielib road and managed the following (too) simple hack in Util.py:
@staticmethod False): '//'): Request( url) if not head_request else HeadRequest(url)
request. add_header( 'User-Agent' , USER_AGENT)
request. add_header( 'Cache- Control' , 'max-age=0')
def urlopen(url, data=None, head_request=
if url.startswith(
url = 'http:' + url
request = urllib2.
# session cookies for wallhaven variety/ cookies/ cookies. txt' 'wallhaven' )>0 and os.path. exists( cookiefile) :
_ , _, _, _, name, value = line.strip( ).split( '\t')
cookies += "%s=%s;" % (name,value)
request. add_header( 'Cookie' , cookies )
cookiefile = '~/.config/
if url.find(
cookies = ''
with open(cookiefile) as CF:
for line in CF:
return urllib2. urlopen( request, data=urllib. urlencode( data) if data else None, timeout=20)
Once Util.py is "fixed" as above, to enable session cookies for wallhaven you just log-on with Firefox to wallhaven and save the session cookies to ~/.config/ variety/ cookies/ cookies. txt by using the Firebug extension