How to use the pycurl.HTTPHEADER function in pycurl

To help you get started, we’ve selected a few pycurl examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github xjdr / xio / int-tests / unsafe_client.py View on Github external
header_line = header_line.decode(_CHAR_ENCODING)
    if ':' not in header_line:
      return
    name, value = header_line.split(':', 1)
    name = name.strip()
    value = value.strip()
    name = name.lower()
    response.headers[name] = value

  buffer = BytesIO()
  curl = pycurl.Curl()
  curl.reset()
  curl.setopt(pycurl.URL, url)
  if headers != None:
    headers = ["{}: {}".format(str(each[0]), str(each[1])) for each in headers.items()]
    curl.setopt(pycurl.HTTPHEADER, headers)
    pass
  curl.setopt(pycurl.WRITEDATA, buffer)
  curl.setopt(pycurl.HTTP_VERSION, pycurl.CURL_HTTP_VERSION_2_0)
  if verbose:
    curl.setopt(curl.VERBOSE, True)
  curl.setopt(pycurl.SSL_VERIFYPEER, 0)
  curl.setopt(pycurl.SSL_VERIFYHOST, 0)
  curl.setopt(pycurl.HEADERFUNCTION, _header_function)
  curl.setopt(pycurl.TIMEOUT, _TIMEOUT_SECS)
  return curl, response, buffer
github lemonad / python-yammer-oauth / yammer.py View on Github external
headers = oauth_request.to_header()
            oauth_request.sign_request(self._signature,
                                       self._consumer,
                                       self._access_token)
            url = oauth_request.to_url()
        except OAuthError, m:
            raise YammerError(m.message)

        if _use_pycurl:
            header_list = []
            for h in headers:
                header_list.append("%s:%s" % (h, headers[h]))

            try:
                content = StringIO.StringIO()
                self._connection.setopt(pycurl.HTTPHEADER, header_list)
                self._connection.setopt(pycurl.URL, url)
                self._connection.setopt(pycurl.WRITEFUNCTION, content.write)
                self._connection.perform()
            except pycurl.error, (n, m):
                raise YammerError(m)

            status = self._connection.getinfo(pycurl.HTTP_CODE)
        else:
            try:
                self._connection.request(oauth_request.http_method,
                                         url,
                                         headers=headers)
            except socket.gaierror, (n, m):
                raise YammerError(m)

            response = self._connection.getresponse()
github videntity / python-omhe / omhe / core / weight.py View on Github external
post_dict['texti']=omhe_dict['texti']
        
        print post_dict
        
        for o in post_dict:
            x=(str(o), str(post_dict[o]))
            pf.append(x)   
        
        
        c = pycurl.Curl()
        c.setopt(pycurl.URL, URL)
        c.setopt(c.SSL_VERIFYPEER, False)
        c.setopt(c.HTTPPOST, pf)
        c.setopt(pycurl.FOLLOWLOCATION, 1)
        c.setopt(pycurl.MAXREDIRS, 5)
        c.setopt(pycurl.HTTPHEADER, ["Accept:"])
        c.setopt(pycurl.USERPWD, user_and_pass)
        c.perform()
        return c
github lyricat / Hotot / hotot-gir / agent.py View on Github external
def _curl(url, params=None, post=False, username=None, password=None, header=None, body=None):
    global pycurl, StringIO
    if not pycurl:
        import pycurl
    try: import cStringIO as StringIO
    except: import StringIO

    curl = pycurl.Curl()

    if get_prefs('use_http_proxy'):
        HTTP_PROXY = '%s:%s' % (get_prefs('http_proxy_host'), get_prefs('http_proxy_port'))
        curl.setopt(pycurl.PROXY, HTTP_PROXY)

    if header:
        curl.setopt(pycurl.HTTPHEADER, [str(k) + ':' + str(v) for k, v in header.items()])

    if post:
        curl.setopt(pycurl.POST, 1)

    if params:
        if post:
            curl.setopt(pycurl.POSTFIELDS, urllib.urlencode(params))
        else:
            url = "?".join((url, urllib.urlencode(params)))

    curl.setopt(pycurl.URL, str(url))

    if username and password:
        curl.setopt(pycurl.USERPWD, "%s:%s" % (str(username), str(password)))

    curl.setopt(pycurl.FOLLOWLOCATION, 1)
github mikeyk / couchdb-lounge / python-lounge / lounge / client / __init__.py View on Github external
curl.setopt(pycurl.TIMEOUT, db_timeout)
		curl.setopt(pycurl.VERBOSE, 1)
		curl.setopt(pycurl.DEBUGFUNCTION, dbg)

		if args is not None:
			url += '?' + urllib.urlencode(args)
		curl.setopt(pycurl.URL, str(url))

		# capture the result in a buffer
		outbuf = StringIO.StringIO()
		curl.setopt(pycurl.WRITEFUNCTION, outbuf.write)

		# POST/PUT body
		if body is not None:
			content_type, body = self._encode(body)
			curl.setopt(pycurl.HTTPHEADER, ['Content-Type: ' + content_type])
			if method=='POST':
				# CURL handles POST differently.  We must set POSTFIELDS
				curl.setopt(pycurl.POSTFIELDS, body)
			else:
				inbuf = StringIO.StringIO(body)
				curl.setopt(pycurl.INFILESIZE, len(body))
				curl.setopt(pycurl.READFUNCTION, inbuf.read)

		if method=='PUT':
			curl.setopt(pycurl.UPLOAD, 1)
		elif method=='POST':
			curl.setopt(pycurl.POST, 1)
		elif method=='DELETE':
			curl.setopt(pycurl.CUSTOMREQUEST, 'DELETE')

		headers = {}
github Juniper / contrail-server-manager / src / client / smgr_monitoring.py View on Github external
def send_REST_request(self, server_ip, port):
        try:
            response = StringIO()
            headers = ["Content-Type:application/json"]
            url = "http://%s:%s/%s" % (server_ip, port, 'MonitorInfo')
            args_str = ''
            conn = pycurl.Curl()
            conn.setopt(pycurl.URL, url)
            conn.setopt(pycurl.HTTPHEADER, headers)
            conn.setopt(pycurl.HTTPGET, 1)
            conn.setopt(pycurl.WRITEFUNCTION, response.write)
            conn.perform()
            data_dict = response.getvalue()
            data_dict = dict(json.loads(data_dict))
            data_list = list(data_dict["__ServerMonitoringInfoTrace_list"]["ServerMonitoringInfoTrace"])
            return data_list
        except Exception as e:
            print "Error is: " + str(e)
            return None
    # end def send_REST_request
github pseiler / savegamesync / savegamesync.py View on Github external
def curl_mv(url, new_url, user, password):
    c = pycurl.Curl()
    c.setopt(c.URL, url)
#    c.setopt(c.VERBOSE, True)
    c.setopt(pycurl.USERPWD, user + ':' + password)
    c.setopt(pycurl.CUSTOMREQUEST, "MOVE")
    c.setopt(pycurl.HTTPHEADER, ["Destination:" + new_url])
    c.perform()
    c.close()
github onap / sdc / catalog-be / src / main / resources / scripts / import / tosca / importNormativeElements.py View on Github external
def createNormativeElement(scheme, be_host, be_port, admin_user, file_dir, url_suffix, element_name, element_form_name,
                           with_metadata=False):
    try:
        log("in create normative element ", element_name)
        buffer = StringIO()
        c = pycurl.Curl()

        url = scheme + '://' + be_host + ':' + be_port + url_suffix
        c.setopt(pycurl.URL, url)
        c.setopt(pycurl.POST, 1)

        admin_header = 'USER_ID: ' + admin_user
        c.setopt(pycurl.HTTPHEADER, [admin_header])

        type_file_name = file_dir + "/" + element_name

        multi_part_form_data = create_multipart_form_data(element_form_name, type_file_name, with_metadata,
                                                          element_name)

        c.setopt(pycurl.HTTPPOST, multi_part_form_data)
        c.setopt(pycurl.WRITEFUNCTION, buffer.write)

        if scheme == 'https':
            # security "man in middle" vulnerability
            c.setopt(pycurl.SSL_VERIFYPEER, 0)
            c.setopt(pycurl.SSL_VERIFYHOST, 0)

        c.perform()
github onap / sdc / asdctool / src / main / resources / scripts / python / user / exportUsers.py View on Github external
def getUsers(scheme, beHost, bePort, adminUser):

	try:
		buffer = StringIO()
		c = pycurl.Curl()

		url = scheme + '://' + beHost + ':' + bePort + ALL_USERS_SUFFIX 
		print(url)
		c.setopt(c.URL, url)
		c.setopt(c.WRITEFUNCTION, buffer.write)
		#c.setopt(c.WRITEFUNCTION, lambda x: None)
		adminHeader = 'USER_ID: ' + adminUser
		c.setopt(pycurl.HTTPHEADER, ['Content-Type: application/json', 'Accept: application/json', adminHeader])

		if scheme == 'https':
			c.setopt(c.SSL_VERIFYPEER, 0)

		res = c.perform()
		#print(res)

		#print('Status: %d' % c.getinfo(c.RESPONSE_CODE))

		c.close()

		body = buffer.getvalue()

        #print(body)

		return (body, None)