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


Python unirest.post函数代码示例

本文整理汇总了Python中unirest.post函数的典型用法代码示例。如果您正苦于以下问题:Python post函数的具体用法?Python post怎么用?Python post使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: _do_async_request

	def _do_async_request(self, url, payload):
		def empty_callback(response):
			pass

		# TODO currently errors when server offline
		# Try catch doesn't work because of threading
		unirest.post(url, headers = {"Accept": "application/json"}, params = payload, callback = empty_callback)
开发者ID:StevenReitsma,项目名称:kaggle-diabetic-retinopathy,代码行数:7,代码来源:plotta.py

示例2: test_predict_recognition

def test_predict_recognition():
    set_unirest_defaults()
    first_image_response = unirest.post(hostname + '/enroll-image/',
        params={"image": open("./arnold.jpg", mode="r"), "label":"Arnold Schwarzenegger"})
    print first_image_response.body
    assert first_image_response.code == 200
    training_set_id = first_image_response.body['id']
    second_image_response = unirest.post(hostname + '/enroll-image/',
        params={"image_url": "http://images.politico.com/global/click/101103_schwarznegger_face_ap_392_regular.jpg", "label":"Arnold Schwarzenegger", "training_set_id":training_set_id})
    assert second_image_response.code == 200
    print second_image_response.body
    third_image_response = unirest.post(hostname + '/enroll-image/',
        params={"image_url": "http://www.theepochtimes.com/n2/images/stories/large/2011/02/08/72460251.jpg", 
        "label":"Donald Rumsfeld", "training_set_id":training_set_id})
    assert third_image_response.code == 200
    #check training set
    training_set_response = unirest.get(hostname + '/trainingset/' + training_set_id)
    print training_set_response.body
    face_images = training_set_response.body['face_images']
    assert len(face_images) == 3
    response = unirest.post(hostname + '/compile-training-set/',
        params={"training_set_id":training_set_id})
    print response.body
    predictive_model_id = response.body['id']
    time.sleep(MODEL_COMPILATION_SECONDS)
    prediction_response = unirest.post(hostname + '/recognize-face/',
        params={"predictive_model_id":predictive_model_id, "image_url":"http://img1.wikia.nocookie.net/__cb20130930223832/armoredheroes/images/3/37/Arnold_Schwarzenegger.jpg"})
    print prediction_response.body
    assert prediction_response.code == 200
    assert prediction_response.body['person']['name'] == "Arnold Schwarzenegger"
开发者ID:danlipert,项目名称:hyperlayer-api-test,代码行数:30,代码来源:test_api.py

示例3: send_sync_data

def send_sync_data(host_list, data, rest_interface):
    print "send_sync_data: start sync data.."
    data_json = json.dumps(data)
    header = {'Content-Type': 'application/json'}
    for cloud in host_list:
        if host_list[cloud][0]:
            host_url = "http://" + host_list[cloud][1] + rest_interface
            print "send_sync_data: host URL: " + host_url + " "
            unirest.post(host_url, headers=header, params=data_json, callback=unirest_callback)
开发者ID:ohaz,项目名称:amos-ss15-proj1,代码行数:9,代码来源:views.py

示例4: found_pop

def found_pop(*args, **kwargs):
    """

    :param args:
    :param kwargs:
    :return:
    """

    url = urljoin(server_addr, make_ext)
    if 'commands' in kwargs:
        url = urljoin(url, "?" + urlencode(kwargs['commands']))
    print unirest.post(url)
开发者ID:austincawley,项目名称:pop,代码行数:12,代码来源:run_pop.py

示例5: getAuth

 def getAuth(self, email, password):
     """Enter your email and password for oc.tc.
     If you don't feel comfortable doing this,
     follow the instructions in AUTHTUTORIAL.md
     to get your auth token."""
     self.return_code = unirest.post(join('http://', self.url, 'players', 'auth'),
         headers={"Content-Type":"application/json", "Authorization":"Basic","Accept":"application/json"},
         params=json.dumps({"email":"{0}".format(email),"password":"{0}".format(password)})).code
     checkCode(self.return_code)
     return str(unirest.post(join('http://', self.url, 'players', 'auth'),
         headers={"Content-Type":"application/json", "Authorization":"Basic","Accept":"application/json"},
         params=json.dumps({"email":"{0}".format(email),"password":"{0}".format(password)})).body['token'])
开发者ID:SunshineAPI,项目名称:sunshine4py,代码行数:12,代码来源:__init__.py

示例6: __imageUpload

    def __imageUpload(self,img,url=False):
        """
        Uploads an image to the camfind api hosted on mashape
        Returns a string token which can be used to retrieve the recognized objects
        
        Parameters
        ----------
        img: file or url
          An image file or url pointing to an image, such as jpeg, to pass to the api

        url: string
          If url is True, the img argument will be interpreted as a url
          instead of a binary image file
        """

        if url == True:
            #configure headers to read an image from an uploaded url
            response = unirest.post("https://camfind.p.mashape.com/image_requests",
              headers={
                "X-Mashape-Key": self.getApiKey(),
                "Content-Type": "application/x-www-form-urlencoded",
                "Accept": "application/json"
              },
              params={
                "image_request[remote_image_url]": img,
                "image_request[altitude]": "27.912109375",
                "image_request[language]": "en",
                "image_request[latitude]": "35.8714220766008",
                "image_request[locale]": "en_US",
                "image_request[longitude]": "14.3583203002251",
              }
            )

        else:
            #configure headers to read an image from local upload
            response = unirest.post("https://camfind.p.mashape.com/image_requests",
              headers={
                "X-Mashape-Key": self.getApiKey(),
              },
              params={
                "image_request[image]": open(img, mode="r"),
                "image_request[altitude]": "27.912109375",
                "image_request[language]": "en",
                "image_request[latitude]": "35.8714220766008",
                "image_request[locale]": "en_US",
                "image_request[longitude]": "14.3583203002251",
              }
            )

        print(response.body)
        return response.body["token"]
开发者ID:rachelelle,项目名称:sustainability,代码行数:51,代码来源:main.py

示例7: test_enroll_image_in_existing_training_set

def test_enroll_image_in_existing_training_set():
    first_image_response = unirest.post(hostname + '/enroll-image/',
        params={"image": open("./arnold.jpg", mode="r"), "label":"Arnold"})
    assert first_image_response.code == 200
    print first_image_response.body
    training_set_id = first_image_response.body['id']
    second_image_response = unirest.post(hostname + '/enroll-image/',
        params={"image": open("./arnold.jpg", mode="r"), "label":"Arnold", "training_set_id":training_set_id})
    assert second_image_response.code == 200
    print second_image_response.body
    #check training set
    training_set_response = unirest.get(hostname + '/trainingset/' + training_set_id + '/')
    print training_set_response.body
    face_images = training_set_response.body['face_images']
    assert len(face_images) == 2
开发者ID:danlipert,项目名称:hyperlayer-api-test,代码行数:15,代码来源:test_api.py

示例8: get_data

def get_data(tweets_data):
	f = open("tweet_data.csv", 'wt')
	writer = csv.writer(f)
	writer.writerow( ('Tweet-Text', 'Tweet-Lang', 'Tweet-country', 'sentiment_type', 'sentiment_score', 'sentiment_result_code', 'sentiment_result_msg') )
	for tweets in tweets_data:
		tweet_text = tweets['text'].encode('ascii', 'ignore')
		response = unirest.post("https://twinword-sentiment-analysis.p.mashape.com/analyze/",
			headers={"X-Mashape-Key": "sGskCbyg1kmshjbTFyTlZCsjHv4vp1MGPV8jsnB1Qfk2Y8Q5Nt",
			"Content-Type": "application/x-www-form-urlencoded",
			"Accept": "application/json"
			},params={"text": tweet_text})
		response_body = response.body
		response_type = response_body['type'].encode('ascii', 'ignore')
		print response_type
		response_score = response_body['score']
		response_result_code = response_body['result_code'].encode('ascii', 'ignore')
		response_result_msg = response_body['result_msg'].encode('ascii', 'ignore')
		sentiment_type.append(response_type)
		sentiment_score.append(response_score)
		sentiment_result_code.append(response_result_code)
		sentiment_result_msg.append(response_result_msg)
		tweet_lang = tweets['lang'].encode('ascii', 'ignore')
		tweet_country = tweets['place']['country'].encode('ascii', 'ignore') if tweets['place'] != None else None
		writer.writerow((tweet_text, tweet_lang, tweet_country, response_type, response_score, response_result_code, response_result_msg) )
	f.close()
	pass
开发者ID:ashrafc,项目名称:twitter-analytics,代码行数:26,代码来源:plot_backup.py

示例9: identify_image

def identify_image(inputFileURL):
    response = unirest.post("https://camfind.p.mashape.com/image_requests",
  headers={
    "X-Mashape-Key": "9UyIuOYhCKmshb72Y27ctmWYJReGp1G3LaBjsndZ3QPhPjjHMl"
  },
  params={
    "focus[x]": "480",
    "focus[y]": "480",
    "image_request[language]": "en",
    "image_request[locale]": "en_US",
    "image_request[remote_image_url]": ""+str(inputFileURL)+""
  }
)

    token = response.body['token'] # The parsed response
    print token
    response2 = unirest.get("https://camfind.p.mashape.com/image_responses/"+str(token),
  headers={
    "X-Mashape-Key": "9UyIuOYhCKmshb72Y27ctmWYJReGp1G3LaBjsndZ3QPhPjjHMl"
  }
)
    time.sleep(1)
    while (response2.body['status'] == 'not completed'):
        response2 = unirest.get("https://camfind.p.mashape.com/image_responses/"+str(token),
    headers={
        "X-Mashape-Key": "9UyIuOYhCKmshb72Y27ctmWYJReGp1G3LaBjsndZ3QPhPjjHMl"
    }
    )
    print "Sleeping"
    time.sleep(1)

    #print response2.body
    print response2.raw_body
开发者ID:b44p,项目名称:b44p,代码行数:33,代码来源:get_street_view_heading.py

示例10: describeImage

def describeImage(imgPath):
	response = unirest.post("https://camfind.p.mashape.com/image_requests",
	  headers={
	    "X-Mashape-Key": "You meshape key, register at meshape https://market.mashape.com/imagesearcher/camfind"
	  },
	  params={
	    "image_request[image]": open(imgPath, mode="r"),
	    "image_request[language]": "en",
	    "image_request[locale]": "en_US"
	  }
	)
	
	token=response.body['token']
	
	response = unirest.get("https://camfind.p.mashape.com/image_responses/" + token,
	  headers={
	    "X-Mashape-Key": "aiYZkTIXj7mshNul9uy1GrEoIZYOp1QdFbGjsn3AexvpbfgD3g",
	    "Accept": "application/json"
	  }
	)
	
	while (response.body['status']!="completed" and response.body['status']!="skipped"):
		time.sleep(1) #sleep for 1 seconds
		response = unirest.get("https://camfind.p.mashape.com/image_responses/" + token,
		  headers={
		    "X-Mashape-Key": "aiYZkTIXj7mshNul9uy1GrEoIZYOp1QdFbGjsn3AexvpbfgD3g",
		    "Accept": "application/json"
		  }
		)
	
	#assume completed
	if (response.body['status']!="skipped"):
		return response.body['name']
	else:
		return "unsuccessful"
开发者ID:ronentk,项目名称:RPI-Visual-Queries,代码行数:35,代码来源:camFind.py

示例11: init_flow

	def init_flow(self, dpid):
		header = {'Content-type':'application/json'}
		body = {'datapathId':"{:0>16x}".format(dpid)}
		LOG.debug("body = " + str(body))
		LOG.info("Request initFlow body = " + str(body))
		res = unirest.post(CONF.ofpm_init_flow_url, headers=header, params=str(body), callback=self.__http_response__)
		return
开发者ID:okinawaopenlabs,项目名称:of-patch-openflow-controller,代码行数:7,代码来源:ofpm.py

示例12: push_daily_crashes_os

def push_daily_crashes_os(os_list):
	response = unirest.post(
		"https://push.geckoboard.com/v1/send/106305-941b1040-d241-4106-a78e-6603c2a29a53",
		headers={"Accept": "application/json", "Content-Type": "application/json"},
		params=json.dumps({
		  "api_key": geckoboard_key,
		  "data": {
  	"item": [
 	   {
 	     "value": os_list[1][0], #os one value
 	     "label": os_list[0][0], #os name
 	   },
 	   {
 	     "value": os_list[1][1], #os two value
 	     "label": os_list[0][1], #os name
 	   },
 	   {                                                                                                                                              
 	     "value": os_list[1][2], #os three value                                                                                                                       
 	     "label": os_list[0][2], #os name                                                                                                                            
 	   },  
 	   {                                                                                                                                              
    	  "value": os_list[1][3], #os three value                                                        
    	  "label": os_list[0][3], #os name                                                                                                                           
    	}  
  	]
	}}))
开发者ID:crittercism-support,项目名称:Crittercism-Geckoboard,代码行数:26,代码来源:geckoboard.py

示例13: __init__

    def __init__(self, url=None):

        #print "here i am"
        if url:
            # retrieve with post method, put for create, get for read, delete for delete
            # unvisitedurls http://localhost:5000/unvisitedurls?start=0&offset=10&spider=6w
            unirest.timeout(180)
            req = unirest.post(url, headers={"Accept":"application/json"})
            self.start_urls = [data['url'] for data in req.body['data']]
            self.name = url[url.find('spider=')+7:]

            self.visitedurldict = OrderedDict()
            self.datadict       = OrderedDict()
            self.filedict       = OrderedDict()
            self.deadurldict    = OrderedDict()

            self.visitedurldict['urls'] = []
            self.datadict['datas']      = []
            self.filedict['files']      = []
            self.deadurldict['urls']    = []

            rules = (
                Rule(sle(allow=("http://book.douban.com/isbn/\d+$")), callback="parse", follow=True),
                Rule(sle(allow=("http://book.douban.com/subject/\d+$")), callback="parse", follow=True),
            )
        # def __del__(self) work
        dispatcher.connect(self.spider_closed, signals.spider_closed)
开发者ID:csrgxtu,项目名称:Sauron,代码行数:27,代码来源:douban.py

示例14: request_token

    def request_token(username, password, scope="*"):
        """Request a new oauth2 token from the Signnow API using unirest

        Args:
            username (str): The email of user you want to create a token for.
            password (str): The account password for the user you want to create a token.
            scope (str): The scope of the token being created.

        Returns:
            dict: The JSON response from the API which includes the attributes of the token
            or the error returned.
        """
        OAUTH2_TOKEN_URL = Config().get_base_url() + '/oauth2/token'
        request = post(OAUTH2_TOKEN_URL, params={
            "username": username,
            "password": password,
            "grant_type": "password",
            "scope": scope
        }, headers={
            "Authorization": "Basic " + Config().get_encoded_credentials(),
            "Accept": "application/json",
            "Content-Type": "application/x-www-form-urlencoded"
        })

        return request.body
开发者ID:signnow,项目名称:SNPythonSDK,代码行数:25,代码来源:oauth2token.py

示例15: test_post

 def test_post(self):
     response = unirest.post("http://httpbin.org/post", params={"name": "Mark", "nick": "thefosk"})
     self.assertEqual(response.code, 200)
     self.assertEqual(len(response.body["args"]), 0)
     self.assertEqual(len(response.body["form"]), 2)
     self.assertEqual(response.body["form"]["name"], "Mark")
     self.assertEqual(response.body["form"]["nick"], "thefosk")
开发者ID:Mondego,项目名称:pyreco,代码行数:7,代码来源:allPythonContent.py


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