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


Python parse.request方法代码示例

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


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

示例1: solve_routes

# 需要导入模块: from urllib import parse [as 别名]
# 或者: from urllib.parse import request [as 别名]
def solve_routes(tokenstuff, service_params):

    # URL to Esri ArcGIS Online asynchronous routing service
    service_url = "http://route.arcgis.com/arcgis/rest/services/World/Route/NAServer/Route_World/solve"

    # Make sure the token isn't about to expire. If it is, wait until it expires and then get a new one.
    now = datetime.datetime.now()
    tokenexpiretime = datetime.datetime.fromtimestamp(tokenstuff['expires'])
    if tokenexpiretime - now < datetime.timedelta(seconds=5):
        time.sleep(5)
        get_token()
        tokenstuff = token

    #Execute the request
    response, response_time = execute_request(service_url, tokenstuff['token'], tokenstuff['referer'], service_params)
    
    return response 
开发者ID:Esri,项目名称:public-transit-tools,代码行数:19,代码来源:AGOLRouteHelper.py

示例2: _do_request

# 需要导入模块: from urllib import parse [as 别名]
# 或者: from urllib.parse import request [as 别名]
def _do_request(self, data):
        """
        使用 urllib 发送数据给服务器,如果发生错误会抛出异常。
        response的结果,会返回
        """
        encoded_data = urllib.urlencode(data).encode('utf8')
        try:
            request = urllib2.Request(self._debug_url_prefix, encoded_data)
            if not self._debug_write_data:      # 说明只检查,不真正写入数据
                request.add_header('Dry-Run', 'true')
            if self._request_timeout is not None:
                response = urllib2.urlopen(request, timeout=self._request_timeout)
            else:
                response = urllib2.urlopen(request)
        except urllib2.HTTPError as e:
            return e
        return response 
开发者ID:sensorsdata,项目名称:sa-sdk-python,代码行数:19,代码来源:sdk.py

示例3: makeHTTPRequest

# 需要导入模块: from urllib import parse [as 别名]
# 或者: from urllib.parse import request [as 别名]
def makeHTTPRequest(url, query_params=None, content_coding_token="gzip", referer=None):
    """Makes an HTTP request and returns the JSON response. content_coding_token
       must be gzip or identity.
       If content_coding_token is identity, response does not need any transformation.
       If content_coding_token is gzip, the response special handling before converting to JSON."""

    response_dict = {}
    if query_params == None:
        query_params = {}
    if not "f" in query_params:
        query_params["f"] = "json"

    request = urllib2.Request(url)
    if ispy3:
        data = urllib.urlencode(query_params)
        binary_data = data.encode('utf-8')
        request.data = binary_data
    else:        
        request.add_data(urllib.urlencode(query_params))
    request.add_header("Accept-Encoding", content_coding_token)
    if referer:
        request.add_header("Referer", referer)
    response = urllib2.urlopen(request)
    if content_coding_token == "gzip":
        if response.info().get("Content-Encoding") == "gzip":
            if ispy3:
                # Encoding is complicated in python3
                buf = sio.BytesIO(response.read())
                response = gzip.GzipFile(fileobj=buf, mode='rb')
                reader = codecs.getreader("utf-8")
                response = reader(response)
            else:
                buf = sio.StringIO(response.read())
                response = gzip.GzipFile(fileobj=buf)
    response_dict = json.load(response)
    return response_dict 
开发者ID:Esri,项目名称:public-transit-tools,代码行数:38,代码来源:AGOLRouteHelper.py

示例4: manual_get_pfam_annotations

# 需要导入模块: from urllib import parse [as 别名]
# 或者: from urllib.parse import request [as 别名]
def manual_get_pfam_annotations(seq, outpath, searchtype='phmmer', force_rerun=False):
    """Retrieve and download PFAM results from the HMMER search tool.

    Args:
        seq:
        outpath:
        searchtype:
        force_rerun:

    Returns:

    Todo:
        * Document and test!

    """
    if op.exists(outpath):
        with open(outpath, 'r') as f:
            json_results = json.loads(json.load(f))

    else:
        fseq = '>Seq\n' + seq
        if searchtype == 'phmmer':
            parameters = {'seqdb': 'pdb', 'seq': fseq}
        if searchtype == 'hmmscan':
            parameters = {'hmmdb': 'pfam', 'seq': fseq}
        enc_params = urllib.urlencode(parameters).encode('utf-8')
        request = urllib2.Request('http://www.ebi.ac.uk/Tools/hmmer/search/{}'.format(searchtype), enc_params)
        url = (urllib2.urlopen(request).geturl() + '?output=json')
        request = str(url)
        request_read = urlopen(request).read().decode("utf-8")

        with open(outpath, 'w') as f:
            json.dump(request_read, f)

        json_results = json.loads(request_read)

    return json_results['results']['hits'] 
开发者ID:SBRG,项目名称:ssbio,代码行数:39,代码来源:hmmer.py

示例5: __request

# 需要导入模块: from urllib import parse [as 别名]
# 或者: from urllib.parse import request [as 别名]
def __request(self, params):
        commonParams = {
            'Format': 'JSON',
            'Version': '2015-01-09',
            'SignatureMethod': 'HMAC-SHA1',
            'SignatureNonce': self.__getSignatureNonce(),
            'SignatureVersion': '1.0',
            'AccessKeyId': self.__appid,
            'Timestamp':  time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime())
        }
        # print(commonParams)

        # merge all params
        finalParams = commonParams.copy()
        finalParams.update(params)

        # signature
        finalParams['Signature'] = self.__signature(finalParams)
        self.__logger.info('Signature'+ str(finalParams['Signature']))
        # get final url
        url = '%s/?%s' % (self.__endpoint, urllib.urlencode(finalParams))
        # print(url)

        request = urllib2.Request(url)
        try:
            f = urllib2.urlopen(request)
            response = f.read()
            self.__logger.info(response.decode('utf-8'))
        except urllib2.HTTPError as e:
            self.__logger.info(e.read().strip().decode('utf-8'))
            raise SystemExit(e) 
开发者ID:broly8,项目名称:letsencrypt-aliyun-dns-manual-hook,代码行数:33,代码来源:aliyun.py

示例6: imgurUpload

# 需要导入模块: from urllib import parse [as 别名]
# 或者: from urllib.parse import request [as 别名]
def imgurUpload(file_path, image_data=None):
	""" Upload the given image to Imgur. 
	
	Arguments:
		file_path: [str] Path to the image file.

	Keyword arguments:
		image_data: [bytes] Read in image in JPG, PNG, etc. format.

	Return:
		img_url: [str] URL to the uploaded image.
	"""

	# Read the image if image data was not given
	if image_data is None:
		
		# Open the image in binary mode
		f = open(file_path, "rb")
		image_data = f.read()


	# Encode the image
	b64_image = base64.standard_b64encode(image_data)


	# Upload the image
	headers = {'Authorization': 'Client-ID ' + CLIENT_ID}
	data = {'image': b64_image, 'title': 'test'} # create a dictionary.

	request = urllib2.Request(url="https://api.imgur.com/3/upload.json", 
		data=urllib.urlencode(data).encode("utf-8"), headers=headers)
	response = urllib2.urlopen(request).read()


	# Get URL to image
	parse = json.loads(response)
	img_url = parse['data']['link']
	

	return img_url 
开发者ID:CroatianMeteorNetwork,项目名称:RMS,代码行数:42,代码来源:ImgurUpload.py


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