Python pycurl.USERPWD Examples
The following are 4
code examples of pycurl.USERPWD().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
pycurl
, or try the search function
.
Example #1
Source File: DataAccess.py From wa with Apache License 2.0 | 7 votes |
def Download_ETens_from_WA_FTP(output_folder, Lat_tiles, Lon_tiles): """ This function retrieves ETensV1.0 data for a given date from the ftp.wateraccounting.unesco-ihe.org server. Restrictions: The data and this python file may not be distributed to others without permission of the WA+ team. Keyword arguments: output_folder -- Directory of the outputs Lat_tiles -- [Lat_min, Lat_max] Tile number of the max and min latitude tile number Lon_tiles -- [Lon_min, Lon_max] Tile number of the max and min longitude tile number """ for v_tile in range(Lat_tiles[0], Lat_tiles[1]+1): for h_tile in range(Lon_tiles[0], Lon_tiles[1]+1): Tilename = "h%sv%s.zip" %(h_tile, v_tile) if not os.path.exists(os.path.join(output_folder,Tilename)): try: # Collect account and FTP information username, password = WebAccounts.Accounts(Type = 'FTP_WA') FTP_name = "ftp://ftp.wateraccounting.unesco-ihe.org//WaterAccounting_Guest/ETensV1.0/%s" % Tilename local_filename = os.path.join(output_folder, Tilename) # Download data from FTP curl = pycurl.Curl() curl.setopt(pycurl.URL, FTP_name) curl.setopt(pycurl.USERPWD, '%s:%s' %(username, password)) fp = open(local_filename, "wb") curl.setopt(pycurl.WRITEDATA, fp) curl.perform() curl.close() fp.close() except: print "tile %s is not found and will be replaced by NaN values" % Tilename return()
Example #2
Source File: dahua_event.py From home-assistant-dahua-event with MIT License | 6 votes |
def __init__(self, hass, config): """Construct a thread listening for events.""" self.hass = hass for device_cfg in config: url = URL_TEMPLATE.format( protocol=device_cfg.get("protocol"), host=device_cfg.get("host"), port=device_cfg.get("port"), events=device_cfg.get("events") ) channels = device_cfg.get("channels") channels_dict = {} if channels is not None: for channel in channels: channels_dict[channel.get("number")] = channel.get("name") device = DahuaDevice(self, hass, device_cfg.get("name"), url, channels_dict) self.Devices.append(device) CurlObj = pycurl.Curl() device.CurlObj = CurlObj CurlObj.setopt(pycurl.URL, url) CurlObj.setopt(pycurl.CONNECTTIMEOUT, 30) CurlObj.setopt(pycurl.TCP_KEEPALIVE, 1) CurlObj.setopt(pycurl.TCP_KEEPIDLE, 30) CurlObj.setopt(pycurl.TCP_KEEPINTVL, 15) CurlObj.setopt(pycurl.HTTPAUTH, pycurl.HTTPAUTH_DIGEST) CurlObj.setopt(pycurl.USERPWD, "%s:%s" % (device_cfg.get("user"), device_cfg.get("password"))) CurlObj.setopt(pycurl.WRITEFUNCTION, device.OnReceive) self.CurlMultiObj.add_handle(CurlObj) self.NumCurlObjs += 1 _LOGGER.debug("Added Dahua device at: %s", url) threading.Thread.__init__(self) self.stopped = threading.Event()
Example #3
Source File: utils.py From marathon-lb with Apache License 2.0 | 4 votes |
def __init__(self, url, auth, verify): self.url = url self.received_buffer = BytesIO() headers = ['Cache-Control: no-cache', 'Accept: text/event-stream'] self.curl = pycurl.Curl() self.curl.setopt(pycurl.URL, url) self.curl.setopt(pycurl.ENCODING, 'gzip') self.curl.setopt(pycurl.CONNECTTIMEOUT, 10) self.curl.setopt(pycurl.WRITEDATA, self.received_buffer) # Marathon >= 1.7.x returns 30x responses for /v2/events responses # when they're coming from a non-leader. So we follow redirects. self.curl.setopt(pycurl.FOLLOWLOCATION, True) self.curl.setopt(pycurl.MAXREDIRS, 1) self.curl.setopt(pycurl.UNRESTRICTED_AUTH, True) # The below settings are to prevent the connection from hanging if the # connection breaks silently. Since marathon-lb only listens, silent # connection failure results in marathon-lb waiting infinitely. # # Minimum bytes/second below which it is considered "low speed". So # "low speed" here refers to 0 bytes/second. self.curl.setopt(pycurl.LOW_SPEED_LIMIT, 1) # How long (in seconds) it's allowed to go below the speed limit # before it times out self.curl.setopt(pycurl.LOW_SPEED_TIME, 300) if auth and type(auth) is DCOSAuth: auth.refresh_auth_header() headers.append('Authorization: %s' % auth.auth_header) elif auth: self.curl.setopt(pycurl.HTTPAUTH, pycurl.HTTPAUTH_BASIC) self.curl.setopt(pycurl.USERPWD, '%s:%s' % auth) if verify: self.curl.setopt(pycurl.CAINFO, verify) else: self.curl.setopt(pycurl.SSL_VERIFYHOST, 0) self.curl.setopt(pycurl.SSL_VERIFYPEER, 0) self.curl.setopt(pycurl.HTTPHEADER, headers) self.curlmulti = pycurl.CurlMulti() self.curlmulti.add_handle(self.curl) self.status_code = 0
Example #4
Source File: reqresp.py From darkc0de-old-stuff with GNU General Public License v3.0 | 4 votes |
def perform(self): self.__performHead="" self.__performBody="" conn=pycurl.Curl() conn.setopt(pycurl.SSL_VERIFYPEER,False) conn.setopt(pycurl.SSL_VERIFYHOST,1) conn.setopt(pycurl.URL,self.completeUrl) if self.__method or self.__userpass: if self.__method=="basic": conn.setopt(pycurl.HTTPAUTH, pycurl.HTTPAUTH_BASIC) elif self.__method=="ntlm": conn.setopt(pycurl.HTTPAUTH, pycurl.HTTPAUTH_NTLM) elif self.__method=="digest": conn.setopt(pycurl.HTTPAUTH, pycurl.HTTPAUTH_DIGEST) conn.setopt(pycurl.USERPWD, self.__userpass) if self.__timeout: conn.setopt(pycurl.CONNECTTIMEOUT, self.__timeout) conn.setopt(pycurl.NOSIGNAL, 1) if self.__totaltimeout: conn.setopt(pycurl.TIMEOUT, self.__totaltimeout) conn.setopt(pycurl.NOSIGNAL, 1) conn.setopt(pycurl.WRITEFUNCTION, self.body_callback) conn.setopt(pycurl.HEADERFUNCTION, self.header_callback) if self.__proxy!=None: conn.setopt(pycurl.PROXY,self.__proxy) if self.__headers.has_key("Proxy-Connection"): del self.__headers["Proxy-Connection"] conn.setopt(pycurl.HTTPHEADER,self.__getHeaders()) if self.method=="POST": conn.setopt(pycurl.POSTFIELDS,self.__postdata) conn.perform() rp=Response() rp.parseResponse(self.__performHead) rp.addContent(self.__performBody) self.response=rp ######### ESTE conjunto de funciones no es necesario para el uso habitual de la clase