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


Python urlfetch.GET属性代码示例

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


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

示例1: call_method

# 需要导入模块: from google.appengine.api import urlfetch [as 别名]
# 或者: from google.appengine.api.urlfetch import GET [as 别名]
def call_method(method, data):
  data.update({'access_token': TOKEN})
  data = urllib.urlencode(data)
  try:
    result = urlfetch.fetch(
        BASE_URL.format(method=method, qs=data),
        method=urlfetch.GET,
        deadline=10)
  except DeadlineExceededError as e:
    logging.exception(e)
    return None
  if result.status_code == 200:
    return json.loads(result.content).get('data')
  else:
    logging.error(result.content)
    return None 
开发者ID:phil-r,项目名称:hackernewsbot,代码行数:18,代码来源:bitly.py

示例2: get

# 需要导入模块: from google.appengine.api import urlfetch [as 别名]
# 或者: from google.appengine.api.urlfetch import GET [as 别名]
def get(self):
        auth_token, _ = app_identity.get_access_token(
            'https://www.googleapis.com/auth/cloud-platform')
        logging.info(
            'Using token {} to represent identity {}'.format(
                auth_token, app_identity.get_service_account_name()))

        response = urlfetch.fetch(
            'https://www.googleapis.com/storage/v1/b?project={}'.format(
                app_identity.get_application_id()),
            method=urlfetch.GET,
            headers={
                'Authorization': 'Bearer {}'.format(auth_token)
            }
        )

        if response.status_code != 200:
            raise Exception(
                'Call failed. Status code {}. Body {}'.format(
                    response.status_code, response.content))

        result = json.loads(response.content)
        self.response.headers['Content-Type'] = 'application/json'
        self.response.write(json.dumps(result, indent=2)) 
开发者ID:GoogleCloudPlatform,项目名称:python-docs-samples,代码行数:26,代码来源:main.py

示例3: list_bucket_files

# 需要导入模块: from google.appengine.api import urlfetch [as 别名]
# 或者: from google.appengine.api.urlfetch import GET [as 别名]
def list_bucket_files(bucket_name, prefix, max_keys=1000):
  """Returns a listing of of a bucket that matches the given prefix."""
  scope = config.GoogleApiScope('devstorage.read_only')
  bucket_url = config.GsBucketURL(bucket_name)
  url = bucket_url + '?'
  query = [('max-keys', max_keys)]
  if prefix:
    query.append(('prefix', prefix))
  url += urllib.urlencode(query)
  auth_token, _ = app_identity.get_access_token(scope)
  result = urlfetch.fetch(url, method=urlfetch.GET, headers={
      'Authorization': 'OAuth %s' % auth_token,
      'x-goog-api-version': '2'})
  if result and result.status_code == 200:
    doc = xml.dom.minidom.parseString(result.content)
    return [node.childNodes[0].data for node in doc.getElementsByTagName('Key')]
  raise BackupValidationError('Request to Google Cloud Storage failed') 
开发者ID:GoogleCloudPlatform,项目名称:python-compat-runtime,代码行数:19,代码来源:backup_handler.py

示例4: get_gs_object

# 需要导入模块: from google.appengine.api import urlfetch [as 别名]
# 或者: from google.appengine.api.urlfetch import GET [as 别名]
def get_gs_object(bucket_name, path):
  """Returns a listing of of a bucket that matches the given prefix."""
  scope = config.GoogleApiScope('devstorage.read_only')
  bucket_url = config.GsBucketURL(bucket_name)
  url = bucket_url + path
  auth_token, _ = app_identity.get_access_token(scope)
  result = urlfetch.fetch(url, method=urlfetch.GET, headers={
      'Authorization': 'OAuth %s' % auth_token,
      'x-goog-api-version': '2'})
  if result and result.status_code == 200:
    return result.content
  if result and result.status_code == 403:
    raise BackupValidationError(
        'Requested path %s is not accessible/access denied' % url)
  if result and result.status_code == 404:
    raise BackupValidationError('Requested path %s was not found' % url)
  raise BackupValidationError('Error encountered accessing requested path %s' %
                              url) 
开发者ID:GoogleCloudPlatform,项目名称:python-compat-runtime,代码行数:20,代码来源:backup_handler.py

示例5: _PopulateX509

# 需要导入模块: from google.appengine.api import urlfetch [as 别名]
# 或者: from google.appengine.api.urlfetch import GET [as 别名]
def _PopulateX509(self):
    with self._x509_init_lock:
      if self._x509 is None:

        url = ('https://www.googleapis.com/service_accounts/v1/metadata/x509/%s'
               % urllib.unquote_plus(self._credentials.service_account_email))
        response = urlfetch.fetch(
            url=url,
            validate_certificate=True,
            method=urlfetch.GET)
        if response.status_code != 200:
          raise apiproxy_errors.ApplicationError(
              app_identity_service_pb.AppIdentityServiceError.UNKNOWN_ERROR,
              'Unable to load X509 cert: %s Response code: %i, Content: %s' % (
                  url, response.status_code, response.content))

        message = 'dummy'
        _, signature = self._credentials.sign_blob(message)

        for signing_key, x509 in json.loads(response.content).items():
          der = rsa.pem.load_pem(x509, 'CERTIFICATE')
          asn1_cert, _ = decoder.decode(der, asn1Spec=Certificate())

          key_bitstring = (
              asn1_cert['tbsCertificate']
              ['subjectPublicKeyInfo']
              ['subjectPublicKey'])
          key_bytearray = BitStringToByteString(key_bitstring)

          public_key = rsa.PublicKey.load_pkcs1(key_bytearray, 'DER')
          try:
            if rsa.pkcs1.verify(message, signature, public_key):
              self._x509 = x509
              self._signing_key = signing_key
              return
          except rsa.pkcs1.VerificationError:
            pass

        raise apiproxy_errors.ApplicationError(
            app_identity_service_pb.AppIdentityServiceError.UNKNOWN_ERROR,
            'Unable to find matching X509 cert for private key: %s' % url) 
开发者ID:GoogleCloudPlatform,项目名称:python-compat-runtime,代码行数:43,代码来源:app_identity_defaultcredentialsbased_stub.py

示例6: __init__

# 需要导入模块: from google.appengine.api import urlfetch [as 别名]
# 或者: from google.appengine.api.urlfetch import GET [as 别名]
def __init__(self, host, port=None, strict=None,
               timeout=_GLOBAL_DEFAULT_TIMEOUT, source_address=None,
               context=None):
    # net.proto.ProcotolBuffer relies on httplib so importing urlfetch at the
    # module level causes a failure on prod. That means the import needs to be
    # lazy.
    from google.appengine.api import urlfetch
    self._fetch = urlfetch.fetch
    self._method_map = {
      'GET': urlfetch.GET,
      'POST': urlfetch.POST,
      'HEAD': urlfetch.HEAD,
      'PUT': urlfetch.PUT,
      'DELETE': urlfetch.DELETE,
      'PATCH': urlfetch.PATCH,
    }
    self.host = host
    self.port = port
    # With urllib2 in Python 2.6, an object can be passed here.
    # The default is set to socket.GLOBAL_DEFAULT_TIMEOUT which is an object.
    # We only accept float, int or long values, otherwise it can be
    # silently ignored.
    if not isinstance(timeout, (float, int, long)):
      timeout = None
    self.timeout = timeout
    # Both 'strict' and 'source_address' are ignored.
    self._method = self._url = None
    self._body = ''
    self.headers = [] 
开发者ID:GoogleCloudPlatform,项目名称:python-compat-runtime,代码行数:31,代码来源:httplib.py

示例7: putrequest

# 需要导入模块: from google.appengine.api import urlfetch [as 别名]
# 或者: from google.appengine.api.urlfetch import GET [as 别名]
def putrequest(self, method, url, skip_host=0, skip_accept_encoding=0):
    """Send a request to the server.

    `method' specifies an HTTP request method, e.g. 'GET'.
    `url' specifies the object being requested, e.g. '/index.html'.
    `skip_host' if True does not add automatically a 'Host:' header
    `skip_accept_encoding' if True does not add automatically an
       'Accept-Encoding:' header

    App Engine Note: `skip_host' and `skip_accept_encoding' are not honored by
        the urlfetch service.
    """
    self._method = method
    self._url = url 
开发者ID:GoogleCloudPlatform,项目名称:python-compat-runtime,代码行数:16,代码来源:httplib.py

示例8: get_remote_app_id

# 需要导入模块: from google.appengine.api import urlfetch [as 别名]
# 或者: from google.appengine.api.urlfetch import GET [as 别名]
def get_remote_app_id(remote_url, extra_headers=None):
  """Get the app_id from the remote_api endpoint.

  This also has the side effect of verifying that it is a remote_api endpoint.

  Args:
    remote_url: The url to the remote_api handler.
    extra_headers: Headers to send (for authentication).

  Returns:
    app_id: The app_id of the target app.

  Raises:
    FetchFailed: Urlfetch call failed.
    ConfigurationError: URLfetch succeeded but results were invalid.
  """
  rtok = str(random.random())[2:]
  url = remote_url + '?rtok=' + rtok
  if not extra_headers:
    extra_headers = {}
  if 'X-appcfg-api-version' not in extra_headers:
    extra_headers['X-appcfg-api-version'] = '1'
  try:
    urlfetch_response = urlfetch.fetch(url, None, urlfetch.GET,
                                       extra_headers, follow_redirects=False,
                                       deadline=10)
  except Exception, e:


    logging.exception('Fetch failed to %s', remote_url)
    raise FetchFailed('Fetch to %s failed: %r' % (remote_url, e)) 
开发者ID:GoogleCloudPlatform,项目名称:python-compat-runtime,代码行数:33,代码来源:remote_api_put_stub.py

示例9: _PopulateX509

# 需要导入模块: from google.appengine.api import urlfetch [as 别名]
# 或者: from google.appengine.api.urlfetch import GET [as 别名]
def _PopulateX509(self):
    with self.__x509_init_lock:
      if not self.__x509:
        url = ('https://www.googleapis.com/service_accounts/v1/metadata/x509/%s'
               % urllib.unquote_plus(self.__email_address))
        resp = urlfetch.fetch(
            url=url,
            validate_certificate=True,
            method=urlfetch.GET)
        if resp.status_code != 200:
          raise apiproxy_errors.ApplicationError(
              app_identity_service_pb.AppIdentityServiceError.UNKNOWN_ERROR,
              'Unable to load X509 cert: %s Response code: %i, Content: %s' % (
                  url, resp.status_code, resp.content))

        msg = 'test'
        sig = rsa.pkcs1.sign(msg, self.__private_key, 'SHA-256')




        for signing_key, x509 in json.loads(resp.content).items():
          der = rsa.pem.load_pem(x509, 'CERTIFICATE')
          asn1_cert, _ = decoder.decode(der, asn1Spec=Certificate())

          key_bitstring = (
              asn1_cert['tbsCertificate']
              ['subjectPublicKeyInfo']
              ['subjectPublicKey'])
          key_bytearray = BitStringToByteString(key_bitstring)

          pub = rsa.PublicKey.load_pkcs1(key_bytearray, 'DER')
          try:
            if rsa.pkcs1.verify(msg, sig, pub):
              self.__x509 = x509
              self.__signing_key = signing_key
              return
          except rsa.pkcs1.VerificationError:
            pass


        raise apiproxy_errors.ApplicationError(
            app_identity_service_pb.AppIdentityServiceError.UNKNOWN_ERROR,
            'Unable to find matching X509 cert for private key: %s' % url) 
开发者ID:GoogleCloudPlatform,项目名称:python-compat-runtime,代码行数:46,代码来源:app_identity_keybased_stub.py

示例10: request

# 需要导入模块: from google.appengine.api import urlfetch [as 别名]
# 或者: from google.appengine.api.urlfetch import GET [as 别名]
def request(self, operation, url, data=None, headers=None):
    """Performs an HTTP call to the server, supports GET, POST, PUT, and
    DELETE.

    Usage example, perform and HTTP GET on http://www.google.com/:
      import atom.http
      client = atom.http.HttpClient()
      http_response = client.request('GET', 'http://www.google.com/')

    Args:
      operation: str The HTTP operation to be performed. This is usually one
          of 'GET', 'POST', 'PUT', or 'DELETE'
      data: filestream, list of parts, or other object which can be converted
          to a string. Should be set to None when performing a GET or DELETE.
          If data is a file-like object which can be read, this method will
          read a chunk of 100K bytes at a time and send them.
          If the data is a list of parts to be sent, each part will be
          evaluated and sent.
      url: The full URL to which the request should be sent. Can be a string
          or atom.url.Url.
      headers: dict of strings. HTTP headers which should be sent
          in the request.
    """
    all_headers = self.headers.copy()
    if headers:
      all_headers.update(headers)

    # Construct the full payload.
    # Assume that data is None or a string.
    data_str = data
    if data:
      if isinstance(data, list):
        # If data is a list of different objects, convert them all to strings
        # and join them together.
        converted_parts = [__ConvertDataPart(x) for x in data]
        data_str = ''.join(converted_parts)
      else:
        data_str = __ConvertDataPart(data)

    # If the list of headers does not include a Content-Length, attempt to
    # calculate it based on the data object.
    if data and 'Content-Length' not in all_headers:
      all_headers['Content-Length'] = len(data_str)

    # Set the content type to the default value if none was set.
    if 'Content-Type' not in all_headers:
      all_headers['Content-Type'] = 'application/atom+xml'

    # Lookup the urlfetch operation which corresponds to the desired HTTP verb.
    if operation == 'GET':
      method = urlfetch.GET
    elif operation == 'POST':
      method = urlfetch.POST
    elif operation == 'PUT':
      method = urlfetch.PUT
    elif operation == 'DELETE':
      method = urlfetch.DELETE
    else:
      method = None
    return HttpResponse(urlfetch.Fetch(url=str(url), payload=data_str,
        method=method, headers=all_headers)) 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:63,代码来源:urlfetch.py

示例11: request

# 需要导入模块: from google.appengine.api import urlfetch [as 别名]
# 或者: from google.appengine.api.urlfetch import GET [as 别名]
def request(self, operation, url, data=None, headers=None):
    """Performs an HTTP call to the server, supports GET, POST, PUT, and
    DELETE.

    Usage example, perform and HTTP GET on http://www.google.com/:
      import atom.http
      client = atom.http.HttpClient()
      http_response = client.request('GET', 'http://www.google.com/')

    Args:
      operation: str The HTTP operation to be performed. This is usually one
          of 'GET', 'POST', 'PUT', or 'DELETE'
      data: filestream, list of parts, or other object which can be converted
          to a string. Should be set to None when performing a GET or DELETE.
          If data is a file-like object which can be read, this method will
          read a chunk of 100K bytes at a time and send them.
          If the data is a list of parts to be sent, each part will be
          evaluated and sent.
      url: The full URL to which the request should be sent. Can be a string
          or atom.url.Url.
      headers: dict of strings. HTTP headers which should be sent
          in the request.
    """
    all_headers = self.headers.copy()
    if headers:
      all_headers.update(headers)

    # Construct the full payload.
    # Assume that data is None or a string.
    data_str = data
    if data:
      if isinstance(data, list):
        # If data is a list of different objects, convert them all to strings
        # and join them together.
        converted_parts = [_convert_data_part(x) for x in data]
        data_str = ''.join(converted_parts)
      else:
        data_str = _convert_data_part(data)

    # If the list of headers does not include a Content-Length, attempt to
    # calculate it based on the data object.
    if data and 'Content-Length' not in all_headers:
      all_headers['Content-Length'] = str(len(data_str))

    # Set the content type to the default value if none was set.
    if 'Content-Type' not in all_headers:
      all_headers['Content-Type'] = 'application/atom+xml'

    # Lookup the urlfetch operation which corresponds to the desired HTTP verb.
    if operation == 'GET':
      method = urlfetch.GET
    elif operation == 'POST':
      method = urlfetch.POST
    elif operation == 'PUT':
      method = urlfetch.PUT
    elif operation == 'DELETE':
      method = urlfetch.DELETE
    else:
      method = None
    return HttpResponse(urlfetch.Fetch(url=str(url), payload=data_str,
        method=method, headers=all_headers, follow_redirects=False)) 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:63,代码来源:appengine.py

示例12: request

# 需要导入模块: from google.appengine.api import urlfetch [as 别名]
# 或者: from google.appengine.api.urlfetch import GET [as 别名]
def request(self, operation, url, data=None, headers=None):
        """Performs an HTTP call to the server, supports GET, POST, PUT, and
        DELETE.

        Usage example, perform and HTTP GET on http://www.google.com/:
          import atom.http
          client = atom.http.HttpClient()
          http_response = client.request('GET', 'http://www.google.com/')

        Args:
          operation: str The HTTP operation to be performed. This is usually one
              of 'GET', 'POST', 'PUT', or 'DELETE'
          data: filestream, list of parts, or other object which can be converted
              to a string. Should be set to None when performing a GET or DELETE.
              If data is a file-like object which can be read, this method will
              read a chunk of 100K bytes at a time and send them.
              If the data is a list of parts to be sent, each part will be
              evaluated and sent.
          url: The full URL to which the request should be sent. Can be a string
              or atom.url.Url.
          headers: dict of strings. HTTP headers which should be sent
              in the request.
        """
        all_headers = self.headers.copy()
        if headers:
            all_headers.update(headers)

        # Construct the full payload.
        # Assume that data is None or a string.
        data_str = data
        if data:
            if isinstance(data, list):
                # If data is a list of different objects, convert them all to strings
                # and join them together.
                converted_parts = [__ConvertDataPart(x) for x in data]
                data_str = ''.join(converted_parts)
            else:
                data_str = __ConvertDataPart(data)

        # If the list of headers does not include a Content-Length, attempt to
        # calculate it based on the data object.
        if data and 'Content-Length' not in all_headers:
            all_headers['Content-Length'] = len(data_str)

        # Set the content type to the default value if none was set.
        if 'Content-Type' not in all_headers:
            all_headers['Content-Type'] = 'application/atom+xml'

        # Lookup the urlfetch operation which corresponds to the desired HTTP verb.
        if operation == 'GET':
            method = urlfetch.GET
        elif operation == 'POST':
            method = urlfetch.POST
        elif operation == 'PUT':
            method = urlfetch.PUT
        elif operation == 'DELETE':
            method = urlfetch.DELETE
        else:
            method = None
        return HttpResponse(urlfetch.Fetch(url=str(url), payload=data_str,
                                           method=method, headers=all_headers)) 
开发者ID:dvska,项目名称:gdata-python3,代码行数:63,代码来源:urlfetch.py


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