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


Python requests.post方法代码示例

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


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

示例1: getTicket

# 需要导入模块: import requests [as 别名]
# 或者: from requests import post [as 别名]
def getTicket():
    # put the ip address or dns of your apic-em controller in this url
    url = "https://" + controller + "/api/v1/ticket"

    #the username and password to access the APIC-EM Controller
    payload = {"username":"usernae","password":"password"}

    #Content type must be included in the header
    header = {"content-type": "application/json"}

    #Performs a POST on the specified url to get the service ticket
    response= requests.post(url,data=json.dumps(payload), headers=header, verify=False)

    #convert response to json format
    r_json=response.json()

    #parse the json to get the service ticket
    ticket = r_json["response"]["serviceTicket"]

    return ticket 
开发者ID:PacktPublishing,项目名称:Mastering-Python-Networking-Second-Edition,代码行数:22,代码来源:cisco_apic_em_1.py

示例2: bindiff_export

# 需要导入模块: import requests [as 别名]
# 或者: from requests import post [as 别名]
def bindiff_export(self, sample, is_64_bit = True, timeout = None):
        """
        Load a sample into IDA Pro, perform autoanalysis and export a BinDiff database.
        :param sample: The sample's path
        :param is_64_bit: If the sample needs to be analyzed by the 64 bit version of IDA
        :param timeout: Timeout for the analysis in seconds
        :return: The file name of the exported bindiff database. The file needs
        to be deleted by the caller. Returns None on error.
        """

        data_to_send = {
            "timeout": timeout,
            "is_64_bit": is_64_bit}
        url = "%s/binexport" % next(self._urls)
        log.debug("curl -XPOST --data '%s' '%s'", json.dumps(data_to_send), url)
        response = requests.post(url, data = data_to_send, files = {os.path.basename(sample): open(sample, "rb")})
        if response.status_code == 200:
            handle, output = tempfile.mkstemp(suffix = ".BinExport")
            with os.fdopen(handle, "wb") as f:
                map(f.write, response.iter_content(1024))
            return output
        else:
            log.error("Bindiff server responded with status code %d: %s", response.status_code, response.content)
            return None 
开发者ID:Cisco-Talos,项目名称:BASS,代码行数:26,代码来源:bindiff.py

示例3: pickle_export

# 需要导入模块: import requests [as 别名]
# 或者: from requests import post [as 别名]
def pickle_export(self, sample, is_64_bit = True, timeout = None):
        """
        Load a sample into IDA Pro, perform autoanalysis and export a pickle file. 
        :param sample: The sample's path
        :param is_64_bit: If the sample needs to be analyzed by the 64 bit version of IDA
        :param timeout: Timeout for the analysis in seconds
        :return: The file name of the exported pickle database. The file needs
        to be deleted by the caller. Returns None on error.
        """

        data_to_send = {
            "timeout": timeout,
            "is_64_bit": is_64_bit}
        url = "%s/pickle" % next(self._urls)
        log.debug("curl -XPOST --data '%s' '%s'", json.dumps(data_to_send), url)
        response = requests.post(url, data = data_to_send, files = {os.path.basename(sample): open(sample, "rb")})
        if response.status_code == 200:
            handle, output = tempfile.mkstemp(suffix = ".pickle")
            with os.fdopen(handle, "wb") as f:
                map(f.write, response.iter_content(1024))
            return output
        else:
            log.error("Bindiff server responded with status code %d: %s", response.status_code, response.content)
            return None 
开发者ID:Cisco-Talos,项目名称:BASS,代码行数:26,代码来源:bindiff.py

示例4: compare

# 需要导入模块: import requests [as 别名]
# 或者: from requests import post [as 别名]
def compare(self, primary, secondary, timeout = None):
        """
        Run BinDiff on the two BinDiff databases.
        :param primary: The first BinExport database
        :param secondary: The second BinExport database
        :param timeout: Timeout for the command in seconds
        :returns: The directory name of the directory with the generated data on the shared volume
        """

        url = "%s/compare" % next(self._urls)
        log.debug("curl -XPOST --form 'timeout=%s' --form 'primary=@%s' --form 'secondary=@%s' '%s'", str(timeout), primary, secondary, url)
        response = requests.post(url, data = {"timeout": timeout}, \
                files = {"primary": open(primary, "rb"), "secondary": open(secondary, "rb")})

        if response.status_code == 200:
            handle, path = tempfile.mkstemp(suffix = ".bindiff.sqlite3")
            with os.fdopen(handle, "wb") as f:
                map(f.write, response.iter_content(1024))
            return path
        else:
            log.error("Bindiff server responded with status code %d: %s", response.status_code, response.content)
            return None 
开发者ID:Cisco-Talos,项目名称:BASS,代码行数:24,代码来源:bindiff.py

示例5: querylanguage

# 需要导入模块: import requests [as 别名]
# 或者: from requests import post [as 别名]
def querylanguage(auth):
    """Query user's language that's available on v2c."""
    default = 'en'

    r = requests.post(
        url=api_url.replace('index.php', 'api.php'),
        data={
            'action': 'query',
            'format': 'json',
            'meta': 'userinfo',
            'uiprop': 'options'
        },
        auth=auth
    )

    try:
        language = r.json()['query']['userinfo']['options']['language']
    except (NameError, KeyError):
        return default

    if not language:
        return default

    return language 
开发者ID:toolforge,项目名称:video2commons,代码行数:26,代码来源:app.py

示例6: post

# 需要导入模块: import requests [as 别名]
# 或者: from requests import post [as 别名]
def post(self, endpoint, args, data=None, files=None, filename=None,
             mode=None):
        if mode == 'nojsondumps':
            headers = {'Content-type': 'application/x-www-form-urlencoded; charset=utf-8'}
            r = requests.post(endpoint, params=args, data=data, headers=headers)
        elif files is None:
            headers = {'Content-type': 'application/json; charset=utf-8'}
            r = requests.post(endpoint, params=args, json=data, headers=headers)
        elif files is not None:
            mimetype = mimetypes.guess_type(files)[0]
            file = {filename: (files, open(files, 'rb'), mimetype)}
            r = requests.post(endpoint, params=args, json=data, files=file)
        r_json = r.json()
        if r_json.get('success'):
            return r_json
        else:
            raise MarketoException(r_json['errors'][0]) 
开发者ID:jepcastelein,项目名称:marketo-rest-python,代码行数:19,代码来源:http_lib.py

示例7: new_post

# 需要导入模块: import requests [as 别名]
# 或者: from requests import post [as 别名]
def new_post(self, text):

        header = {
            "Content-Type": "application/json",
            "User-Agent" : self.UA,
            "X-Line-Mid" : self.mid,
            "x-lct" : self.channel_access_token,
        }

        payload = {
            "postInfo" : { "readPermission" : { "type" : "ALL" } },
            "sourceType" : "TIMELINE",
            "contents" : { "text" : text }
        }

        r = requests.post(
            "http://" + self.host + "/mh/api/v24/post/create.json",
            headers = header,
            data = json.dumps(payload)
        )

        return r.json() 
开发者ID:CyberTKR,项目名称:CyberTK-Self,代码行数:24,代码来源:channel.py

示例8: postPhoto

# 需要导入模块: import requests [as 别名]
# 或者: from requests import post [as 别名]
def postPhoto(self,text,path):
        header = {
            "Content-Type": "application/json",
            "User-Agent" : self.UA,
            "X-Line-Mid" : self.mid,
            "x-lct" : self.channel_access_token,
        }

        payload = {
            "postInfo" : { "readPermission" : { "type" : "ALL" } },
            "sourceType" : "TIMELINE",
            "contents" : { "text" : text ,"media" :  [{u'objectId': u'F57144CF9ECC4AD2E162E68554D1A8BD1a1ab0t04ff07f6'}]}
        }
        r = requests.post(
            "http://" + self.host + "/mh/api/v24/post/create.json",
            headers = header,
            data = json.dumps(payload)
        )

        return r.json() 
开发者ID:CyberTKR,项目名称:CyberTK-Self,代码行数:22,代码来源:channel.py

示例9: like

# 需要导入模块: import requests [as 别名]
# 或者: from requests import post [as 别名]
def like(self, mid, postid, likeType=1001):

        header = {
            "Content-Type" : "application/json",
            "X-Line-Mid" : self.mid,
            "x-lct" : self.channel_access_token,
        }

        payload = {
            "likeType" : likeType,
            "activityExternalId" : postid,
            "actorId" : mid
        }

        r = requests.post(
            "http://" + self.host + "/mh/api/v23/like/create.json?homeId=" + mid,
            headers = header,
            data = json.dumps(payload)
        )

        return r.json() 
开发者ID:CyberTKR,项目名称:CyberTK-Self,代码行数:23,代码来源:channel.py

示例10: comment

# 需要导入模块: import requests [as 别名]
# 或者: from requests import post [as 别名]
def comment(self, mid, postid, text):
        header = {
            "Content-Type" : "application/json",
            "X-Line-Mid" : self.mid,
            "x-lct" : self.channel_access_token,
        }

        payload = {
            "commentText" : text,
            "activityExternalId" : postid,
            "actorId" : mid
        }

        r = requests.post(
            "http://" + self.host + "/mh/api/v23/comment/create.json?homeId=" + mid,
            headers = header,
            data = json.dumps(payload)
        )

        return r.json() 
开发者ID:CyberTKR,项目名称:CyberTK-Self,代码行数:22,代码来源:channel.py

示例11: createAlbum

# 需要导入模块: import requests [as 别名]
# 或者: from requests import post [as 别名]
def createAlbum(self,gid,name):
        header = {
                    "Content-Type": "application/json",
                    "User-Agent" : self.UA,
                    "X-Line-Mid" : self.mid,
                    "x-lct" : self.channel_access_token,
        }
        payload = {
                "type" : "image",
                "title" : name
        }
        r = requests.post(
            "http://" + self.host + "/mh/album/v3/album?count=1&auto=0&homeId=" + gid,
            headers = header,
            data = json.dumps(payload)
        )
        return r.json() 
开发者ID:CyberTKR,项目名称:CyberTK-Self,代码行数:19,代码来源:channel.py

示例12: post_image

# 需要导入模块: import requests [as 别名]
# 或者: from requests import post [as 别名]
def post_image(self):
    try:
      self.image_b64()
    except Exception as e: raise Exception("Image cant be converted.");
    payload = "data=data:image/jpeg;base64," + self.b64img
    payload += '&filter=*&trial=4'
    header = {
      'Host':'whatanime.ga',
      'accept':'application/json, text/javascript, */*; q=0.01',
      'content-type':'application/x-www-form-urlencoded; charset=UTF-8',
      'origin':'https://whatanime.ga',
      'referer':'https://whatanime.ga/',
      'user-agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36',
      'x-requested-with':'XMLHttpRequest',
    }
    r = requests.post('https://whatanime.ga/search', data=payload, headers=header)
    if r.status_code == 200:
      return r.json()
    else:
      raise Exception("Post failed.") 
开发者ID:CyberTKR,项目名称:CyberTK-Self,代码行数:22,代码来源:LineApi.py

示例13: _must_post

# 需要导入模块: import requests [as 别名]
# 或者: from requests import post [as 别名]
def _must_post(self, api, data=None, json=None, timeout=10, **kwargs):
        if data is not None:
            kwargs['data'] = data
        elif json is not None:
            kwargs['json'] = json
        else:
            kwargs['data'] = {}
        kwargs['timeout'] = timeout

        try:
            r = requests.post(api, **kwargs)
            return r
        except requests.exceptions.Timeout:
            logger.error("Timeout requesting Gitter")
        except KeyboardInterrupt:
            raise
        except:
            logger.exception("Unknown error requesting Gitter")
        return None 
开发者ID:tuna,项目名称:fishroom,代码行数:21,代码来源:gitter.py

示例14: upload_image

# 需要导入模块: import requests [as 别名]
# 或者: from requests import post [as 别名]
def upload_image(self, filename=None, filedata=None, **kwargs) -> str:
        if filedata is None:
            files = {"image": open(filename, 'rb')}
        else:
            files = {"image": filedata}

        try:
            r = requests.post(self.url, files=files, timeout=5)
        except requests.exceptions.Timeout:
            logger.error("Timeout uploading to VimCN")
            return None
        except:
            logger.exception("Unknown errror uploading to VimCN")
            return None
        if not r.ok:
            return None
        return r.text.strip() 
开发者ID:tuna,项目名称:fishroom,代码行数:19,代码来源:photostore.py

示例15: comparetext

# 需要导入模块: import requests [as 别名]
# 或者: from requests import post [as 别名]
def comparetext (text1, text2, api=__ls_api):
  """
  Computes the semantic similarity between two given text strings. Returns a score between [-1, 1].

  Parameters
  ----------
  text1 : string

  text2 : string

  api : string (default=cloud release endpoint)
      The endpoint you wish to hit for the concept labeling task. Default is the release version of the Microsoft Academic Language Similarity API.    
  """
  body = {
    "Text1": text1,
    "Text2": text2
  }
  endpoint = api + 'comparetext'
  resp = requests.post(endpoint, json=body)
  assert resp.status_code == 200, endpoint + " failed with status: " + str(resp.status_code)
  return float(resp.content) 
开发者ID:graph-knowledgegraph,项目名称:KDD2019-HandsOn-Tutorial,代码行数:23,代码来源:5.Recommendations.py


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