我正在尝试向远程网页发出Get方法请求,并用请求发送标头。当我得到正确的cookies头时,请保持正确的值:
有谁能告诉我如何修复这个错误并提出正确的Get方法请求?我应该输入我丢失的利比亚文吗?提前谢谢。在
代码:import urllib,urllib2,re,xbmcplugin,xbmcgui,sys,os,xbmc,xbmcaddon
import cookielib,requests,json
import requests
def myfunction(url):
cj = cookielib.CookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
resp = opener.open(url)
resp2 = opener.open('http://www.awebsite.com/test/api.php')
html_data = resp2.read()
pattern = re.compile('"X-hello-data",\s?"(.*?)"')
xhellodata = pattern.search(html_data).groups()[0]
myheaders = {'Cookie' : cookies, 'User-Agent' : 'XBMC', 'Referer' : 'http://www.awebsite.com/main.php', 'X-hello-data' : xhellodata}
itemurl = 'http://www.awebsite.com/ajax.php?season=winter&type=2&name=test'
r = http.request('GET', itemurl, headers=myheaders)
print r;
itemurl2 = urllib.unquote(r.data)
print 'valueofItemUrl2'
print itemurl2;
错误:
^{pr2}$