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


Python urlfetch.POST属性代码示例

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


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

示例1: call_method

# 需要导入模块: from google.appengine.api import urlfetch [as 别名]
# 或者: from google.appengine.api.urlfetch import POST [as 别名]
def call_method(method, data):
  data = json.dumps(data)
  try:
    result = urlfetch.fetch(
        BASE_URL.format(token=TOKEN, method=method),
        payload=data,
        method=urlfetch.POST,
        deadline=10,
        headers={'Content-Type': 'application/json'})
  except DeadlineExceededError as e:
    logging.exception(e)
    return None
  if result.status_code == 200:
    return json.loads(result.content)
  else:
    logging.error(result.content)
    return None 
开发者ID:phil-r,项目名称:hackernewsbot,代码行数:19,代码来源:telegram.py

示例2: call_method

# 需要导入模块: from google.appengine.api import urlfetch [as 别名]
# 或者: from google.appengine.api.urlfetch import POST [as 别名]
def call_method(method, data):
  data.update({'key': TOKEN})
  data = json.dumps(data)
  try:
    result = urlfetch.fetch(
        BASE_URL.format(method=method, api_key=TOKEN),
        payload=data,
        method=urlfetch.POST,
        deadline=10,
        headers={'Content-Type': 'application/json'})
  except DeadlineExceededError as e:
    logging.exception(e)
    return None
  if result.status_code == 200:
    return json.loads(result.content)
  else:
    logging.error(result.content)
    return None 
开发者ID:phil-r,项目名称:hackernewsbot,代码行数:20,代码来源:googl.py

示例3: test_get

# 需要导入模块: from google.appengine.api import urlfetch [as 别名]
# 或者: from google.appengine.api.urlfetch import POST [as 别名]
def test_get(
      self, mock_config, mock_urlfetch, mock_app_identity, mock_logging):
    test_destination_url = cloud_datastore_export._DESTINATION_URL
    test_bucket_name = 'gcp_bucket_name'
    mock_config.side_effect = [test_bucket_name, True]
    expected_url = (
        cloud_datastore_export._DATASTORE_API_URL % self.test_application_id)
    mock_urlfetch.return_value.status_code = httplib.OK
    now = datetime.datetime(
        year=2017, month=1, day=1, hour=1, minute=1, second=15)
    with freezegun.freeze_time(now):
      self.testapp.get(self._CRON_URL)
      mock_urlfetch.assert_called_once_with(
          url=expected_url,
          payload=json.dumps({
              'project_id': self.test_application_id,
              'output_url_prefix': test_destination_url.format(
                  test_bucket_name, now.strftime('%Y_%m_%d-%H%M%S'))
          }),
          method=urlfetch.POST,
          deadline=60,
          headers={
              'Content-Type': 'application/json',
              'Authorization': 'Bearer mock_token'})
      self.assertEqual(mock_logging.call_count, 3) 
开发者ID:google,项目名称:loaner,代码行数:27,代码来源:cloud_datastore_export_test.py

示例4: send_request

# 需要导入模块: from google.appengine.api import urlfetch [as 别名]
# 或者: from google.appengine.api.urlfetch import POST [as 别名]
def send_request(fields):
    config = model.Config.get()

    fields["VERSION"] = "113"
    fields["USER"] =  config.paypal_user
    fields["PWD"] =  config.paypal_password
    fields["SIGNATURE"] = config.paypal_signature

    form_data = urllib.urlencode(fields)

    result = urlfetch.fetch(url=config.paypal_api_url, payload=form_data, method=urlfetch.POST,
                headers={'Content-Type': 'application/x-www-form-urlencoded'})
    result_map = urlparse.parse_qs(result.content)

    if 'ACK' in result_map:
        if result_map['ACK'][0] == "Success":
            return (True, result_map)
   
        logging.warning("Paypal returned an error:")
        logging.warning(pprint.pformat(result_map))
        return (False, result_map)

    logging.warning("Could not contact Paypal:")
    logging.warning(result.content)
    return False, result.content 
开发者ID:MayOneUS,项目名称:pledgeservice,代码行数:27,代码来源:paypal.py

示例5: push_important_news

# 需要导入模块: from google.appengine.api import urlfetch [as 别名]
# 或者: from google.appengine.api.urlfetch import POST [as 别名]
def push_important_news():
    key = request.values.get('key')
    news = ndb.Key(urlsafe=key).get()
    form_fields = {
        "token": app.config["PUSHOVER_APP_KEY"],
        "user": app.config["PUSHOVER_USER_KEY"],
        "message": news.summary.encode("utf-8"),
        "url": news.link.encode("utf-8"),
        "url_title": u"点击访问正文".encode("utf-8"),
        "title": news.title.encode("utf-8"),
    }
    form_data = urllib.urlencode(form_fields)
    urlfetch.fetch(url=app.config["PUSH_OVER_URL"],
                   payload=form_data,
                   method=urlfetch.POST,
                   headers={'Content-Type': 'application/x-www-form-urlencoded'},
                   follow_redirects=False,
                   validate_certificate=False)
    return "Done", 200 
开发者ID:liantian-cn,项目名称:RSSNewsGAE,代码行数:21,代码来源:background.py

示例6: get_file_info

# 需要导入模块: from google.appengine.api import urlfetch [as 别名]
# 或者: from google.appengine.api.urlfetch import POST [as 别名]
def get_file_info(self, access_token, name):

		headers = {
			'Content-Type' : 'application/json',
			'Authorization' : 'Bearer ' + access_token
		}

		data = {
    		"path": "/" + name,
		    "include_media_info": False,
		    "include_deleted": False,
		    "include_has_explicit_shared_members": False
		}

		result = urlfetch.fetch(
			payload=json.dumps(data),
			method=urlfetch.POST,
			url='https://api.dropboxapi.com/2/files/get_metadata',
			headers=headers
		)

		if result.status_code != 200:
			raise Exception("Failed to get file metadata from Dropbox. Status: %s, body: %s" % (result.status_code, result.content))
		self.log(result.content)
		return json.loads(result.content) 
开发者ID:einaregilsson,项目名称:MyLife,代码行数:27,代码来源:dropbox.py

示例7: _MakeRemoteSyncCall

# 需要导入模块: from google.appengine.api import urlfetch [as 别名]
# 或者: from google.appengine.api.urlfetch import POST [as 别名]
def _MakeRemoteSyncCall(self, service, call, request, response):
    """Send an RPC to a remote_api endpoint."""
    request_pb = remote_api_pb.Request()
    request_pb.set_service_name(service)
    request_pb.set_method(call)
    request_pb.set_request(request.Encode())

    response_pb = remote_api_pb.Response()
    encoded_request = request_pb.Encode()
    try:
      urlfetch_response = urlfetch.fetch(self.remote_url, encoded_request,
                                         urlfetch.POST, self.extra_headers,
                                         follow_redirects=False,
                                         deadline=10)
    except Exception, e:


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

示例8: _send_to_bitpay

# 需要导入模块: from google.appengine.api import urlfetch [as 别名]
# 或者: from google.appengine.api.urlfetch import POST [as 别名]
def _send_to_bitpay(self, amountCents, temp_key_str):
    price_in_dollars = int(amountCents) / 100.0
    apiKey = model.Secrets.get().bitpay_api_key
    uname = base64.b64encode(apiKey)
    headers = {'Authorization': 'Basic ' + uname }

    callbackUrl = self.request.host_url + "/r/bitcoin_notifications"
    logging.info('CALLBACK URL WILL BE: ' + callbackUrl)

    post_data = {
      'posData': temp_key_str,
      'price': price_in_dollars,
      'notificationURL': self.request.host_url + "/r/bitcoin_notifications",
      'currency': 'USD',
      # 'buyerName': data["name"],
      # 'buyerEmail': data["email"]
    }

    payload = urllib.urlencode(post_data)
    logging.info('calling URL fetchee')

    result = urlfetch.fetch(
      url='https://bitpay.com/api/invoice/',
      payload=payload,
      method=urlfetch.POST,
      headers=headers,
      validate_certificate=True
    )

    if result.status_code == 200:
      response_dict = json.loads(result.content)
      return response_dict
    else:
      logging.warning('BitcoinStart failed: ' + str(result.content))
      self.error(400)
      self.response.write('Invalid request')
      return 
开发者ID:MayOneUS,项目名称:pledgeservice,代码行数:39,代码来源:handlers.py

示例9: launch_fetch

# 需要导入模块: from google.appengine.api import urlfetch [as 别名]
# 或者: from google.appengine.api.urlfetch import POST [as 别名]
def launch_fetch():
    feeds = get_quarterly_feed_key()
    now = datetime.now(tz=app.config["TIME_ZONE"])
    if now.minute / 15 == 3:
        feeds += get_hourly_feed_key()
    if now.hour == 9 and now.minute / 15 == 1:
        feeds += get_daily_feed_key()
    for feed in feeds:
        taskqueue.add(queue_name='fetch-queue',
                      url=url_for("fetch_one_feed"),
                      method='POST',
                      params={"key": feed.urlsafe()}
                      )
    return "Done", 200 
开发者ID:liantian-cn,项目名称:RSSNewsGAE,代码行数:16,代码来源:background.py

示例10: fetch_one_feed

# 需要导入模块: from google.appengine.api import urlfetch [as 别名]
# 或者: from google.appengine.api.urlfetch import POST [as 别名]
def fetch_one_feed():
    key = request.values.get('key')
    feed = ndb.Key(urlsafe=key).get()
    parser = url2parser(feed.url)
    if parser is not None:
        the_last_fetch = feed.latest_fetch
        feed.latest_fetch = datetime.now()
        list_of_news_entities = []
        ndb.put_multi(list_of_news_entities)
        for entry in parser.entries:
            if check_entry(entry):
                entry.published = datetime.fromtimestamp(mktime(entry.published_parsed))
                if entry.published > the_last_fetch:
                    news_entry = NewsEntry()
                    news_entry.published = entry.published
                    news_entry.title = entry.title
                    news_entry.link = entry.link
                    news_entry.summary = clean_html(entry.summary)
                    news_entry.feed = feed.title
                    list_of_news_entities.append(news_entry)
        feed.put()
        news_key_list = ndb.put_multi(list_of_news_entities)
        for news_key in news_key_list:
            taskqueue.add(queue_name='collect-queue',
                          url=url_for("collect_keyword_for_one_news"),
                          method='POST',
                          params={"key": news_key.urlsafe()}
                          )
        return "Done", 200
    else:
        return "parser is None", 200 
开发者ID:liantian-cn,项目名称:RSSNewsGAE,代码行数:33,代码来源:background.py

示例11: collect_keyword_for_one_news

# 需要导入模块: from google.appengine.api import urlfetch [as 别名]
# 或者: from google.appengine.api.urlfetch import POST [as 别名]
def collect_keyword_for_one_news():
    user_key_word = get_pure_keyword()
    key = request.values.get('key')
    news = ndb.Key(urlsafe=key).get()
    form_fields = {
        "text": news.summary.encode("utf-8"),
        "topK": app.config["TOP_KEYWORD"],
        "withWeight": 0
    }
    form_data = urllib.urlencode(form_fields)
    result = urlfetch.fetch(url=app.config["JIEBA_API"],
                            payload=form_data,
                            method=urlfetch.POST,
                            headers={'Content-Type': 'application/x-www-form-urlencoded'},
                            follow_redirects=False)
    json_content = json.loads(result.content)
    key_words = json_content["result"]
    del news.key_word[:]
    news.key_word = key_words
    tmp = [val for val in key_words if val in user_key_word]
    if tmp:
        news.important = True
    if tmp and app.config["PUSHOVER"]:
        taskqueue.add(queue_name='push-msg-queue',
                      url=url_for("push_important_news"),
                      method='POST',
                      params={"key": key})
    news.put()
    return "Done", 200 
开发者ID:liantian-cn,项目名称:RSSNewsGAE,代码行数:31,代码来源:background.py

示例12: put_file

# 需要导入模块: from google.appengine.api import urlfetch [as 别名]
# 或者: from google.appengine.api.urlfetch import POST [as 别名]
def put_file(self, access_token, name, bytes):

#		info = self.get_file_info(access_token, name)
#		self.log(info)

		dropbox_args = {
    		"path": "/" + name,
    		"mode": { ".tag" : "overwrite"},
    		"autorename": True,
    		"mute": False
		}

		headers = {
			'Content-Type' : 'application/octet-stream',
			'Authorization' : 'Bearer ' + access_token,
			'Dropbox-API-Arg' : json.dumps(dropbox_args)
		}

		result = urlfetch.fetch(
			payload=bytes,
			method=urlfetch.POST,
			url='https://content.dropboxapi.com/2/files/upload',
			headers=headers
		)

		if result.status_code != 200:
			self.log(result.content)
			raise Exception("Failed to send file to Dropbox. Status: %s, body: %s" % (result.status_code, result.content))
		return json.loads(result.content) 
开发者ID:einaregilsson,项目名称:MyLife,代码行数:31,代码来源:dropbox.py

示例13: get

# 需要导入模块: from google.appengine.api import urlfetch [as 别名]
# 或者: from google.appengine.api.urlfetch import POST [as 别名]
def get(self):
        # [START urlfetch-post]
        try:
            form_data = urllib.urlencode(UrlPostHandler.form_fields)
            headers = {'Content-Type': 'application/x-www-form-urlencoded'}
            result = urlfetch.fetch(
                url='http://localhost:8080/submit_form',
                payload=form_data,
                method=urlfetch.POST,
                headers=headers)
            self.response.write(result.content)
        except urlfetch.Error:
            logging.exception('Caught exception fetching url')
        # [END urlfetch-post] 
开发者ID:GoogleCloudPlatform,项目名称:python-docs-samples,代码行数:16,代码来源:main.py

示例14: __init__

# 需要导入模块: from google.appengine.api import urlfetch [as 别名]
# 或者: from google.appengine.api.urlfetch import POST [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

示例15: get

# 需要导入模块: from google.appengine.api import urlfetch [as 别名]
# 或者: from google.appengine.api.urlfetch import POST [as 别名]
def get(self):
    bucket_name = config_model.Config.get('gcp_cloud_storage_bucket')
    if config_model.Config.get('enable_backups') and bucket_name:
      access_token, _ = app_identity.get_access_token(
          'https://www.googleapis.com/auth/datastore')

      # We strip the first 2 characters because os.environ.get returns the
      # application id with a partitiona separated by tilde, eg `s~`, which is
      # not needed here.
      app_id = constants.APPLICATION_ID.split('~')[1]

      request = {
          'project_id': app_id,
          'output_url_prefix': _format_full_path(bucket_name),
      }
      headers = {
          'Content-Type': 'application/json',
          'Authorization': 'Bearer ' + access_token
      }

      logging.info(
          'Attempting to export cloud datastore to bucket %r.', bucket_name)
      try:
        result = urlfetch.fetch(
            url=_DATASTORE_API_URL % app_id,
            payload=json.dumps(request),
            method=urlfetch.POST,
            deadline=60,
            headers=headers)
        if result.status_code == httplib.OK:
          logging.info('Cloud Datastore export completed.')
          logging.info(result.content)
        elif result.status_code >= 500:
          logging.error(result.content)
        else:
          logging.warning(result.content)
        self.response.status_int = result.status_code
      except urlfetch.Error:
        logging.error('Failed to initiate datastore export.')
        self.response.status_int = httplib.INTERNAL_SERVER_ERROR
    else:
      logging.info('Backups are not enabled, skipping.') 
开发者ID:google,项目名称:loaner,代码行数:44,代码来源:cloud_datastore_export.py


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