当前位置: 首页>>代码示例>>Python>>正文


Python Request.read方法代码示例

本文整理汇总了Python中urllib2.Request.read方法的典型用法代码示例。如果您正苦于以下问题:Python Request.read方法的具体用法?Python Request.read怎么用?Python Request.read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在urllib2.Request的用法示例。


在下文中一共展示了Request.read方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: myPlexSignin

# 需要导入模块: from urllib2 import Request [as 别名]
# 或者: from urllib2.Request import read [as 别名]
def myPlexSignin(username,password):
    try:

        if username != '' and password != '':
            print "Fetching myPlex authentication token."
            headers={}
            headers["Authorization"] = "Basic %s" % base64.encodestring('%s:%s' % (username, password)).replace('\n', '')
            headers["X-Plex-Client-Identifier"] = quote(base64.encodestring(str(uuid.getnode())).replace('\n', ''))
            headers["X-Plex-Product"] = "Plex-Downloader"
            headers["X-Plex-Device"] = "Plex-Downloader"
            headers["X-Plex-Device-Name"] = socket.gethostname()
            headers["X-Plex-Platform"] = platform.system()
            headers["X-Plex-Client-Platform"] = platform.system()
            headers["X-Plex-Platform-Version"] = platform.version()
            headers["X-Plex-Provides"] = "controller"
            r = Request("https://plex.tv/users/sign_in.xml", data="", headers=headers)
            r = urlopen(r)

            compiled = re.compile("<authentication-token>(.*)<\/authentication-token>", re.DOTALL)
            authtoken = compiled.search(r.read()).group(1).strip()
            if authtoken != None:
                return authtoken
                print "Successfully authenticated with myPlex!"
            else:
                print "Failed to login to myPlex!"
                return authtoken
        else:
            authtoken = ""

    except Exception, e:
        print "Failed to login to myPlex: %s" % str(e)
开发者ID:Copro,项目名称:PlexDownloader,代码行数:33,代码来源:webui.py

示例2: URLThread

# 需要导入模块: from urllib2 import Request [as 别名]
# 或者: from urllib2.Request import read [as 别名]
class URLThread(Thread):
    def __init__(self,url):
        super(URLThread, self).__init__()
        self.url = url
        self.response = None

    def run(self):
        self.request = Request(self.url, None, 
                                {'Referer' : 'http://inpho.cogs.indiana.edu'})
        self.request = urlopen(self.request)
        self.response = self.request.read()
开发者ID:camerontt2000,项目名称:inphosite,代码行数:13,代码来源:multi_get.py

示例3: _call_api

# 需要导入模块: from urllib2 import Request [as 别名]
# 或者: from urllib2.Request import read [as 别名]
 def _call_api(self, url, data=None):
     '''Makes the call to the specified API, passing the session auth token
        via the X-tableau-auth header. This function reads the result.
        If the result includes XML, the function returns an ElementTree object,
        otherwise it returns the HTTP status code.
     '''
     req = Request(url, headers = {'X-tableau-auth': self.token}, data=data)
     req = urlopen(req)
     resp = req.read().decode("utf8")
     if self._is_xml(req):
         return ET.fromstring(resp)
     else:
         return req.getcode()
开发者ID:thbeh,项目名称:tableau-api,代码行数:15,代码来源:example.py

示例4: myPlexSignin

# 需要导入模块: from urllib2 import Request [as 别名]
# 或者: from urllib2.Request import read [as 别名]
def myPlexSignin(username,password):
	try:
		if os.path.isfile('token.txt'):
			with open('token.txt', 'r') as f:
				authtoken = f.readline()
			print "Using cached myPlex token."
			return authtoken
		elif username != '' and password != '':
			print "Fetching myPlex authentication token."
			headers={}
			headers["Authorization"] = "Basic %s" % base64.encodestring('%s:%s' % (username, password)).replace('\n', '')
			headers["X-Plex-Client-Identifier"] = quote(base64.encodestring(str(uuid.getnode())).replace('\n', ''))
			headers["X-Plex-Product"] = "Plex-Downloader"
			headers["X-Plex-Device"] = "Plex-Downloader"
			headers["X-Plex-Device-Name"] = socket.gethostname()
			headers["X-Plex-Platform"] = platform.system()
			headers["X-Plex-Client-Platform"] = platform.system()
			headers["X-Plex-Platform-Version"] = platform.version()
			headers["X-Plex-Provides"] = "controller"
			r = Request("https://plex.tv/users/sign_in.xml", data="", headers=headers)
			r = urlopen(r)
			compiled = re.compile("<authentication-token>(.*)<\/authentication-token>", re.DOTALL)
			authtoken = compiled.search(r.read()).group(1).strip()
			if authtoken != None:
				f = open('token.txt','w+')
				f.write(authtoken)
				f.close()
				if myplexshared == "enable":
					link = "https://plex.tv/pms/system/library/sections?X-Plex-Token="+authtoken
					f = urllib.urlopen(link)
					serverlist = f.read()
					tokens = re.findall("accessToken\=\"(.*?)\"", serverlist)
					tokens =  list(set(tokens))
					tokens.remove(authtoken)
					authtoken = tokens[0]
					f = open('token.txt','w+')
					f.write(authtoken)
					f.close()
					return authtoken
					print "Successfully grabbed shared myPlex Tokens!"
				else:
					return authtoken
					print "Successfully authenticated with myPlex!"
			else:
				print "Failed to login to myPlex!"
				return authtoken
		else:
			authtoken = ""

	except Exception, e:
		print "Failed to login to myPlex: %s" % str(e)
开发者ID:buchanan,项目名称:PlexDownloader,代码行数:53,代码来源:myplex.py

示例5: index

# 需要导入模块: from urllib2 import Request [as 别名]
# 或者: from urllib2.Request import read [as 别名]
def index():
        url = 'http://www.gvsu.edu/'
        req = Request(url)
        req = urlopen(req)
        soup = BeautifulSoup(req.read())
        closed_div = soup.find("div", {"id": "gvsu-crisis_alert"})
        is_closed = False
        if closed_div:
            closed_div.h2.extract()
            details = closed_div.text
            closed = "Yes."
            is_closed = True
        else:
            closed = "No."
            details = ""
        return render_template('closed.html',closed=closed,details=details,is_closed=is_closed, users=get_actice_users())
开发者ID:jonbloom,项目名称:gvclosed,代码行数:18,代码来源:gvclosed.py

示例6: fetch_menu

# 需要导入模块: from urllib2 import Request [as 别名]
# 或者: from urllib2.Request import read [as 别名]
   def fetch_menu(args):

      from bs4 import BeautifulSoup
      from urllib2 import build_opener, Request
      from urllib import urlencode

      (html, user_agent)= args

      parser= BeautifulSoup(html, "html").find("a", class_= "menu-explore")
      if parser:
         url= parser["href"]
         request= Request('http://yelp.com' + url)
         request.add_header('User-Agent', user_agent)
         opener= build_opener()
         request= opener.open(request)
         response= request.read()
      else:
         url= None
         response= None

      return (url, response)
开发者ID:richardjmarini,项目名称:Impetus,代码行数:23,代码来源:yelp.py

示例7: fetch_next_url

# 需要导入模块: from urllib2 import Request [as 别名]
# 或者: from urllib2.Request import read [as 别名]
   def fetch_next_url(args):

      from bs4 import BeautifulSoup
      from urllib2 import build_opener, Request
      from urllib import urlencode

      (html, user_agent)= args

      parser= BeautifulSoup(html, "html").find_all("a", class_= "page-option prev-next")
      url= None
      response= None
      for prevnext in parser:
         url= prevnext["href"]
         print "FOUND", url
      print "USING", url
      request= Request('http://yelp.com' + url)
      request.add_header('User-Agent', user_agent)
      opener= build_opener()
      request= opener.open(request)
      response= request.read()

      return (url, response)
开发者ID:richardjmarini,项目名称:Impetus,代码行数:24,代码来源:yelp.py

示例8: myPlexSignin

# 需要导入模块: from urllib2 import Request [as 别名]
# 或者: from urllib2.Request import read [as 别名]
    def myPlexSignin(self, username = '', password = ''):
        try:

            username = htpc.settings.get('plex_username', '')
            password = htpc.settings.get('plex_password', '')

            if username != '' and password != '':
                self.logger.debug("Fetching auth token")
                headers={}
                headers["Authorization"] = "Basic %s" % base64.encodestring('%s:%s' % (username, password)).replace('\n', '')
                headers["X-Plex-Client-Identifier"] = quote(base64.encodestring(str(uuid.getnode())).replace('\n', ''))
                headers["X-Plex-Product"] = "HTPC-Manager"
                headers["X-Plex-Device"] = "HTPC-Manager"
                headers["X-Plex-Device-Name"] = socket.gethostname()
                headers["X-Plex-Platform"] = platform.system()
                headers["X-Plex-Client-Platform"] = platform.system()
                headers["X-Plex-Platform-Version"] = platform.version()
                headers["X-Plex-Provides"] = "controller"
                r = Request("https://plex.tv/users/sign_in.xml", data="", headers=headers)
                r = urlopen(r)

                compiled = re.compile("<authentication-token>(.*)<\/authentication-token>", re.DOTALL)
                authtoken = compiled.search(r.read()).group(1).strip()


                if authtoken != None:
                    htpc.settings.set('plex_authtoken', authtoken)
                    return "Logged in to myPlex"
                else:
                    return "Failed to loggin to myPlex"
            else:
                if htpc.settings.get('plex_authtoken', '') != '':
                    htpc.settings.set('plex_authtoken', '')
                    self.logger.debug("Removed myPlex Token")
                return
        except Exception, e:
            self.logger.error("Exception: " + str(e))
            return "Failed to logg in to myPlex: %s" % str(e)
开发者ID:KaHooli,项目名称:HTPC-Manager,代码行数:40,代码来源:plex.py

示例9: __open

# 需要导入模块: from urllib2 import Request [as 别名]
# 或者: from urllib2.Request import read [as 别名]
 def __open(self, url):
   req = Request(url, headers = {
     'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11',
     'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
     'Accept-Charset': 'ISO-8859-1,utf-8;q=0.7,*;q=0.3',
     'Accept-Encoding': 'none',
     'Accept-Language': 'en-US,en;q=0.8',
     'Connection': 'keep-alive'})
   
   start = dt.now()
   
   req = None
   try:
     req = urlopen(url)
     self.html_src = req.read()
   except Exception as e:
     self.req_err = e
   else:
     if self.req_err is not None:
       req.close()
   
   self.req_time = dt.now() - start
     
   return self.html_src
开发者ID:rhewett,项目名称:nhlscrapi,代码行数:26,代码来源:nhlreq.py

示例10: urlopen

# 需要导入模块: from urllib2 import Request [as 别名]
# 或者: from urllib2.Request import read [as 别名]
else:
   print 'Logged in to FitDay. Saved cookie to '+COOKIE_FILE+'.'

# Download weight data
nexturl = 'https://www.fitday.com/fitness/WeightHistory.html'

while nexturl != '':
   # Load the cookie and visit the URL of interest.
   cookieJar.load(COOKIE_FILE)
   while True:
      try:
         req = urlopen(nexturl)
         break
      except:
         print "Error reading the URL. Trying again..."
   htmlSource = req.read()
   req.close()
   
   # Filter the result a bit.
   htmlSource = htmlSource[11:]
   htmlSource = htmlSource.replace('\\"','"')
   htmlSource = htmlSource.replace('\\n','\n')
   htmlSource = htmlSource.replace('\\t','\t')
   
   soup = BeautifulSoup(''.join(htmlSource))
   
   to_extract = soup.findAll('script') # removing JS
   for item in to_extract:
      item.extract()
   
   weight_table = soup.find('div', {'class' : 'ListView'}).table
开发者ID:btrettel,项目名称:medos,代码行数:33,代码来源:FitDay.py


注:本文中的urllib2.Request.read方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。