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


Python request.Request方法代码示例

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


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

示例1: authenticate

# 需要导入模块: from six.moves.urllib import request [as 别名]
# 或者: from six.moves.urllib.request import Request [as 别名]
def authenticate(self, url, params):
        """
        returns a request object ready to be issued to the Mixpanel API
        """
        params['api_key'] = self.client.api_key
        params['expire'] = int(time.time()) + self.DEFAULT_EXPIRATION

        # Creating signature
        if 'sig' in params:
            del params['sig']
        params['sig'] = self._hash_args(params, self.client.api_secret)

        request_url = '{base_url}?{encoded_params}'.format(
            base_url=url,
            encoded_params=_unicode_urlencode(params)
        )
        return url_request.Request(request_url) 
开发者ID:cooncesean,项目名称:mixpanel-query-py,代码行数:19,代码来源:auth.py

示例2: _download_all_metadata

# 需要导入模块: from six.moves.urllib import request [as 别名]
# 或者: from six.moves.urllib.request import Request [as 别名]
def _download_all_metadata(url):
    """
    Downloads the json file that contains all of the metadata for a specific file type (read:
    audio files, benchmark files, or trained models) that is on the EFZ server. This is retrieved
    from one of following three URLs (which are stored in nussl.constants):
    NUSSL_EFZ_AUDIO_METADATA_URL, NUSSL_EFZ_BENCHMARK_METADATA_URL, or NUSSL_EFZ_MODEL_METADATA_URL.

    Args:
        url (str):  URL for the EFZ server that has metadata. One of these three:
            NUSSL_EFZ_AUDIO_METADATA_URL, NUSSL_EFZ_BENCHMARK_METADATA_URL, or
            NUSSL_EFZ_MODEL_METADATA_URL.

    Returns:
        (list): List of dicts with metadata for the desired file type.

    """
    request = Request(url)

    # Make sure to get the newest data
    request.add_header('Pragma', 'no-cache')
    request.add_header('Cache-Control', 'max-age=0')
    try:
        return json.loads(urlopen(request).read())
    except:
        raise NoConnectivityError("Can't connect to internet") 
开发者ID:nussl,项目名称:nussl,代码行数:27,代码来源:efz_utils.py

示例3: grab_artifact_from_jenkins

# 需要导入模块: from six.moves.urllib import request [as 别名]
# 或者: from six.moves.urllib.request import Request [as 别名]
def grab_artifact_from_jenkins(**context):
        """
        Grab an artifact from the previous job
        The python-jenkins library doesn't expose a method for that
        But it's totally possible to build manually the request for that
        """
        hook = JenkinsHook("your_jenkins_connection")
        jenkins_server = hook.get_jenkins_server()
        url = context['task_instance'].xcom_pull(task_ids='trigger_job')
        # The JenkinsJobTriggerOperator store the job url in the xcom variable corresponding to the task
        # You can then use it to access things or to get the job number
        # This url looks like : http://jenkins_url/job/job_name/job_number/
        url = url + "artifact/myartifact.xml"  # Or any other artifact name
        request = Request(url)
        response = jenkins_server.jenkins_open(request)
        return response  # We store the artifact content in a xcom variable for later use 
开发者ID:apache,项目名称:airflow,代码行数:18,代码来源:example_jenkins_job_trigger.py

示例4: _request

# 需要导入模块: from six.moves.urllib import request [as 别名]
# 或者: from six.moves.urllib.request import Request [as 别名]
def _request(self, req_body=None, method=None,
                 header=constants.CONTENT_TYPE_URLENCODE):
        req = url_request.Request(self._url, req_body.encode(), header)
        if method not in (None, 'GET', 'POST'):
            req.get_method = lambda: method
        self._http_log_req(req)
        try:
            resp = self.url_opener.open(req)
            resp_body = resp.read()
            self._http_log_resp(resp, resp_body)
        except url_error.HTTPError as http_err:
            if '403' == six.text_type(http_err.code):
                raise exception.NotAuthorized()
            else:
                err = {'errorCode': -1,
                       'httpStatusCode': http_err.code,
                       'messages': six.text_type(http_err),
                       'request': req_body}
                msg = (_("The request is invalid. Reason: %(reason)s") %
                       {'reason': err})
                raise exception.ManilaException(message=msg)

        return resp_body 
开发者ID:openstack,项目名称:manila,代码行数:25,代码来源:connector.py

示例5: DetectGce

# 需要导入模块: from six.moves.urllib import request [as 别名]
# 或者: from six.moves.urllib.request import Request [as 别名]
def DetectGce():
    """Determine whether or not we're running on GCE.

    This is based on:
      https://cloud.google.com/compute/docs/metadata#runninggce

    Returns:
      True iff we're running on a GCE instance.
    """
    metadata_url = 'http://{}'.format(
        os.environ.get('GCE_METADATA_ROOT', 'metadata.google.internal'))
    try:
        o = urllib_request.build_opener(urllib_request.ProxyHandler({})).open(
            urllib_request.Request(
                metadata_url, headers={'Metadata-Flavor': 'Google'}))
    except urllib_error.URLError:
        return False
    return (o.getcode() == http_client.OK and
            o.headers.get('metadata-flavor') == 'Google') 
开发者ID:google,项目名称:apitools,代码行数:21,代码来源:util.py

示例6: upload_disk

# 需要导入模块: from six.moves.urllib import request [as 别名]
# 或者: from six.moves.urllib.request import Request [as 别名]
def upload_disk(self, fileItem, lease, host):
        """
        Upload an individual disk. Passes the file handle of the
        disk directly to the urlopen request.
        """
        ovffile = self.get_disk(fileItem, lease)
        if ovffile is None:
            return
        deviceUrl = self.get_device_url(fileItem, lease)
        url = deviceUrl.url.replace('*', host)
        headers = {'Content-length': get_tarfile_size(ovffile)}
        if hasattr(ssl, '_create_unverified_context'):
            sslContext = ssl._create_unverified_context()
        else:
            sslContext = None
        req = Request(url, ovffile, headers)
        urlopen(req, context=sslContext) 
开发者ID:vmware,项目名称:pyvmomi-community-samples,代码行数:19,代码来源:deploy_ova.py

示例7: fetch_saml_validation

# 需要导入模块: from six.moves.urllib import request [as 别名]
# 或者: from six.moves.urllib.request import Request [as 别名]
def fetch_saml_validation(self, ticket):
        # We do the SAML validation
        headers = {
            'soapaction': 'http://www.oasis-open.org/committees/security',
            'cache-control': 'no-cache',
            'pragma': 'no-cache',
            'accept': 'text/xml',
            'connection': 'keep-alive',
            'content-type': 'text/xml; charset=utf-8',
        }
        params = [('TARGET', self.service_url)]
        saml_validate_url = urllib_parse.urljoin(
            self.server_url, 'samlValidate',
        )
        request = Request(
            saml_validate_url + '?' + urllib_parse.urlencode(params),
            self.get_saml_assertion(ticket),
            headers,
        )
        return urllib_request.urlopen(request) 
开发者ID:nitmir,项目名称:django-cas-server,代码行数:22,代码来源:cas.py

示例8: invoke_storlet_on_copy_dest

# 需要导入模块: from six.moves.urllib import request [as 别名]
# 或者: from six.moves.urllib.request import Request [as 别名]
def invoke_storlet_on_copy_dest(self):
        # No COPY in swiftclient. Using urllib instead...
        url = '%s/%s/%s' % (self.url, self.container, self.storlet_file)
        headers = {'X-Auth-Token': self.token,
                   'X-Run-Storlet': self.storlet_name,
                   'X-Object-Meta-Name': 'thumbnail',
                   'Destination': '%s/gen_thumb_on_copy_.jpg' % self.container}
        headers.update(self.additional_headers)
        req = Request(url, headers=headers)
        req.get_method = lambda: 'COPY'
        conn = urlopen(req, timeout=10)
        status = conn.getcode()
        self.assertIn(status, [201, 202])

        headers = c.head_object(self.url, self.token,
                                self.container, 'gen_thumb_on_copy_.jpg')
        self.assertLess(int(headers['content-length']), 1087318)
        self.assertEqual('thumbnail', headers['x-object-meta-name'])
        self.assertTrue('x-object-meta-x-timestamp' not in headers)
        self.assertTrue('x-timestamp' in headers) 
开发者ID:openstack,项目名称:storlets,代码行数:22,代码来源:test_thumbnail_storlet.py

示例9: _get_content

# 需要导入模块: from six.moves.urllib import request [as 别名]
# 或者: from six.moves.urllib.request import Request [as 别名]
def _get_content(url):
  """Opens the url and loads the response into json."""
  logging.info('opening url %s', url)
  req = request.Request(url)
  resp = request.urlopen(req)
  resp_text = _as_text(resp.read())
  logging.info('response text = %s', resp_text)
  return json.loads(resp_text) 
开发者ID:tensorflow,项目名称:benchmarks,代码行数:10,代码来源:tpu_runtime_utils.py

示例10: _query_iedb

# 需要导入模块: from six.moves.urllib import request [as 别名]
# 或者: from six.moves.urllib.request import Request [as 别名]
def _query_iedb(request_values, url):
    """
    Call into IEDB's web API for MHC binding prediction using request dictionary
    with fields:
        - "method"
        - "length"
        - "sequence_text"
        - "allele"

    Parse the response into a DataFrame.
    """
    data = urlencode(request_values)
    req = Request(url, data.encode("ascii"))
    response = urlopen(req).read()
    return _parse_iedb_response(response) 
开发者ID:openvax,项目名称:mhctools,代码行数:17,代码来源:iedb.py

示例11: request_gce_metadata

# 需要导入模块: from six.moves.urllib import request [as 别名]
# 或者: from six.moves.urllib.request import Request [as 别名]
def request_gce_metadata(path):
  req = Request('http://metadata/computeMetadata/v1/%s' % path,
                headers={'Metadata-Flavor': 'Google'})
  resp = urlopen(req, timeout=2)
  return tf.compat.as_str(resp.read()) 
开发者ID:mlperf,项目名称:training_results_v0.5,代码行数:7,代码来源:tfrecords_to_bigtable.py

示例12: get_json

# 需要导入模块: from six.moves.urllib import request [as 别名]
# 或者: from six.moves.urllib.request import Request [as 别名]
def get_json(baseurl, parameters={}, headers={}):
    '''Download Data from an URL and returns it as JSON
    @param url Url to download from
    @param parameters Parameter dict to be encoded with url
    @param headers Headers dict to pass with Request
    @returns JSON Object with data from URL
    '''
    jsonString = download(baseurl, parameters, headers)
    jsonDict = json.loads(jsonString)
    log.debug(json.dumps(jsonDict, indent=4, sort_keys=True))
    return jsonDict 
开发者ID:ingwinlu,项目名称:python-twitch,代码行数:13,代码来源:scraper.py

示例13: download

# 需要导入模块: from six.moves.urllib import request [as 别名]
# 或者: from six.moves.urllib.request import Request [as 别名]
def download(baseurl, parameters={}, headers={}):
    '''Download Data from an url and returns it as a String
    @param baseurl Url to download from (e.g. http://www.google.com)
    @param parameters Parameter dict to be encoded with url
    @param headers Headers dict to pass with Request
    @returns String of data from URL
    '''
    url = '?'.join([baseurl, urlencode(parameters)])
    log.debug('Downloading: ' + url)
    data = ""
    for _ in range(MAX_RETRIES):
        try:
            req = Request(url, headers=headers)
            req.add_header(USER_AGENT, USER_AGENT_STRING)
            response = urlopen(req)
            if six.PY2:
                data = response.read()
            else:
                data = response.read().decode('utf-8')
            response.close()
            break
        except Exception as err:
            if not isinstance(err, URLError):
                log.debug("Error %s during HTTP Request, abort", repr(err))
                raise  # propagate non-URLError
            log.debug("Error %s during HTTP Request, retrying", repr(err))
    else:
        raise
    return data 
开发者ID:ingwinlu,项目名称:python-twitch,代码行数:31,代码来源:scraper.py

示例14: _do_setup

# 需要导入模块: from six.moves.urllib import request [as 别名]
# 或者: from six.moves.urllib.request import Request [as 别名]
def _do_setup(self):
        credential = ('user=' + self.username
                      + '&password=' + self.password
                      + '&Login=Login')
        req = url_request.Request(self.auth_url, credential.encode(),
                                  constants.CONTENT_TYPE_URLENCODE)
        resp = self.url_opener.open(req)
        resp_body = resp.read()
        self._http_log_resp(resp, resp_body) 
开发者ID:openstack,项目名称:manila,代码行数:11,代码来源:connector.py

示例15: assertUrl

# 需要导入模块: from six.moves.urllib import request [as 别名]
# 或者: from six.moves.urllib.request import Request [as 别名]
def assertUrl(self, url):

            prefix, path = url.split(':', 1)
            if prefix == 'file':
                self.assertTrue(os.path.exists(path))
            else:
                try:
                    urlopen(Request(url))
                except:
                    self.fail() 
开发者ID:DataBiosphere,项目名称:toil,代码行数:12,代码来源:jobStoreTest.py


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