Python urllib.urlencode() Examples
The following are 30
code examples of urllib.urlencode().
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
urllib
, or try the search function
.
Example #1
Source File: senddata.py From PiPark with GNU General Public License v2.0 | 7 votes |
def post_request(vals, url): """ Build a post request. Args: vals: Dictionary of (field, values) for the POST request. url: URL to send the data to. Returns: Dictionary of JSON response or error info. """ # Build the request and send to server data = urllib.urlencode(vals) try: request = urllib2.Request(url, data) response = urllib2.urlopen(request) except urllib2.HTTPError, err: return {"error": err.reason, "error_code": err.code}
Example #2
Source File: sms.py From Servo with BSD 2-Clause "Simplified" License | 7 votes |
def send(self, note, number): conf = Configuration.conf() if not conf.get('sms_http_url'): raise ValueError(_("No SMS HTTP gateway defined")) params = urllib.urlencode({ 'username' : conf['sms_http_user'], 'password' : conf['sms_http_password'], 'text' : note.body.encode('utf8'), 'to' : number }) f = urllib.urlopen("%s?%s" % (conf['sms_http_url'], params), context=_create_unverified_context()) return f.read()
Example #3
Source File: jf-web.py From jawfish with MIT License | 6 votes |
def run_simulation(self): global TARGET, ADDR, VULN_VAR, TIMEOUT, REQ_TOTAL,\ METHOD, OTHER_VARIABLES tmp = OTHER_VARIABLES tmp[VULN_VAR] = self.genome try: if METHOD == 0: prep = urllib.urlencode(tmp) r = urllib.urlopen('http://%s/%s' % (TARGET, ADDR), data=prep, timeout=TIMEOUT) else: prep = urllib.urlencode(tmp) req = urllib.Request('http://%s/%s' % (TARGET, ADDR), data=prep) r = urllib.urlopen(req) REQ_TOTAL += 1 self.m_text['text'] = r.get_data() self.m_text['url'] = r.get_full_url() self.m_text['status_code'] = r.getcode() except: pass return self.m_text
Example #4
Source File: request.py From plugin.video.emby with GNU General Public License v3.0 | 6 votes |
def request_encode_url(self, method, url, fields=None, headers=None, **urlopen_kw): """ Make a request using :meth:`urlopen` with the ``fields`` encoded in the url. This is useful for request methods like GET, HEAD, DELETE, etc. """ if headers is None: headers = self.headers extra_kw = {'headers': headers} extra_kw.update(urlopen_kw) if fields: url += '?' + urlencode(fields) return self.urlopen(method, url, **extra_kw)
Example #5
Source File: sms.py From Servo with BSD 2-Clause "Simplified" License | 6 votes |
def send(self): pwhash = md5(self.conf['sms_http_password']).hexdigest() params = { 'username' : self.conf['sms_http_user'], 'password' : pwhash, 'message' : self.body, 'from' : self.sender, 'to' : self.recipient, } if self.msg: dlruri = settings.SERVO_URL + '/api/messages/?id={0}'.format(self.msg.code) params['notify_url'] = dlruri params = urllib.urlencode(params) r = urllib.urlopen(self.URL, params, context=_create_unverified_context()).read() if 'ERROR:' in r: raise ValueError(self.ERRORS.get(r, _('Unknown error (%s)') % r))
Example #6
Source File: api.py From plugin.video.emby with GNU General Public License v3.0 | 6 votes |
def get_backdrops(self, item_id, tags, query=None): ''' Get backdrops based of "BackdropImageTags" in the emby object. ''' query = list(query) if query else [] backdrops = [] if item_id is None: return backdrops for index, tag in enumerate(tags): query.append(('Tag', tag)) artwork = "%s/emby/Items/%s/Images/Backdrop/%s?%s" % (self.server, item_id, index, urllib.urlencode(query)) if not self.verify_ssl: artwork += "|verifypeer=false" backdrops.append(artwork) return backdrops
Example #7
Source File: http.py From Paradrop with Apache License 2.0 | 6 votes |
def urlEncodeParams(data): """ Return data URL-encoded. This function specifically handles None and boolean values to convert them to JSON-friendly strings (e.g. None -> 'null'). """ copy = dict() for key, value in six.iteritems(data): if value is None: copy[key] = 'null' elif isinstance(value, bool): copy[key] = json.dumps(value) else: copy[key] = value return urllib.urlencode(copy, doseq=True)
Example #8
Source File: polarflowexport.py From polar-flow-export with Apache License 2.0 | 6 votes |
def _execute_request(self, path, post_params=None): url = "https://flow.polar.com%s" % path self._logger.debug("Requesting '%s'" % url) if post_params != None: postData = urllib.urlencode(post_params) else: postData = None try: response = self._url_opener.open(url, postData) data = response.read() except Exception, e: self._logger.error("Error fetching %s: %s" % (url, e)) raise Exception(e)
Example #9
Source File: note.py From Servo with BSD 2-Clause "Simplified" License | 6 votes |
def send_sms_builtin(self, recipient, sender=None): """ Sends SMS through built-in gateway """ if not settings.SMS_HTTP_URL: raise ValueError(_('System is not configured for built-in SMS support.')) if sender is None: location = self.created_by.location sender = location.title data = urllib.urlencode({ 'username' : settings.SMS_HTTP_USERNAME, 'password' : settings.SMS_HTTP_PASSWORD, 'numberto' : recipient.replace(' ', ''), 'numberfrom': sender.encode(SMS_ENCODING), 'message' : self.body.encode(SMS_ENCODING), }) from ssl import _create_unverified_context f = urllib.urlopen(settings.SMS_HTTP_URL, data, context=_create_unverified_context()) return f.read()
Example #10
Source File: request.py From recruit with Apache License 2.0 | 6 votes |
def request_encode_url(self, method, url, fields=None, headers=None, **urlopen_kw): """ Make a request using :meth:`urlopen` with the ``fields`` encoded in the url. This is useful for request methods like GET, HEAD, DELETE, etc. """ if headers is None: headers = self.headers extra_kw = {'headers': headers} extra_kw.update(urlopen_kw) if fields: url += '?' + urlencode(fields) return self.urlopen(method, url, **extra_kw)
Example #11
Source File: bing.py From sqliv with GNU General Public License v3.0 | 6 votes |
def search(self, query, stop=100): ''' :type query : str :param query: Query for search :type stop : int :param stop : Last result to retrieve. :rtype: list ''' links = [] start = 1 for page in range(int(round(int(stop), -1)) / 10): URL = (self.bingsearch % (urllib.urlencode({'q': query}))) + '&first=' + str(start) html = self.get_page(URL) result = self.parse_links(html) [links.append(_) for _ in result if _ not in links] start = start + 10 return links
Example #12
Source File: reverseip.py From sqliv with GNU General Public License v3.0 | 6 votes |
def reverseip(url): """return domains from given the same server""" # get only domain name url = urlparse(url).netloc if urlparse(url).netloc != '' else urlparse(url).path.split("/")[0] source = "http://domains.yougetsignal.com/domains.php" useragent = useragents.get() contenttype = "application/x-www-form-urlencoded; charset=UTF-8" # POST method opener = urllib2.build_opener( urllib2.HTTPHandler(), urllib2.HTTPSHandler()) data = urllib.urlencode([('remoteAddress', url), ('key', '')]) request = urllib2.Request(source, data) request.add_header("Content-type", contenttype) request.add_header("User-Agent", useragent) try: result = urllib2.urlopen(request).read() except urllib2.HTTPError, e: print >> sys.stderr, "[{}] HTTP error".format(e.code)
Example #13
Source File: api.py From google_streetview with MIT License | 6 votes |
def __init__( self, params, site_api='https://maps.googleapis.com/maps/api/streetview', site_metadata='https://maps.googleapis.com/maps/api/streetview/metadata'): # (params) Set default params defaults = { 'size': '640x640' } for i in range(len(params)): for k in defaults: if k not in params[i]: params[i][k] = defaults[k] self.params = params # (image) Create image api links from parameters self.links = [site_api + '?' + urlencode(p) for p in params] # (metadata) Create metadata api links and data from parameters self.metadata_links = [site_metadata + '?' + urlencode(p) for p in params] self.metadata = [requests.get(url, stream=True).json() for url in self.metadata_links]
Example #14
Source File: sutils.py From plugin.video.sosac.ph with GNU General Public License v2.0 | 6 votes |
def getTVDB(self, name, id): if id: data = util.request('http://thetvdb.com/api/GetSeriesByRemoteID.php?imdbid=tt' + id + '&language=all') tvid = re.search('<id>(\d+)</id>', data) if tvid: return tvid.group(1) shortname = re.search('(.+) (\(\d{4}\))', name).group(1) urllang = [urllib.urlencode({'seriesname': shortname, 'language': 'cs'}), urllib.urlencode({'seriesname': shortname, 'language': 'all'}), urllib.urlencode({'seriesname': name, 'language': 'cs'}), urllib.urlencode({'seriesname': name, 'language': 'all'})] for iter in urllang: data = util.request('http://thetvdb.com/api/GetSeries.php?' + iter) tvid = re.search('<id>(\d+)</id>', data) if tvid: return tvid.group(1) return None
Example #15
Source File: device.py From wechatpy with MIT License | 6 votes |
def get_qrcode_url(self, ticket, data=None): """ 通过 ticket 换取二维码地址 详情请参考 https://iot.weixin.qq.com/wiki/new/index.html?page=3-4-4 :param ticket: 二维码 ticket :param data: 额外数据 :return: 二维码地址 """ url = f"https://we.qq.com/d/{ticket}" if data: if isinstance(data, (dict, tuple, list)): data = urllib.urlencode(data) data = to_text(base64.b64encode(to_binary(data))) url = f"{url}#{data}" return url
Example #16
Source File: web_request_socket.py From httpninja with Apache License 2.0 | 6 votes |
def _setParams(self): parsedURL = urlparse.urlparse(self.url) # setting the path if self.useAbsolutePath == True: self._path = self.url else: self._path = parsedURL.path self.qs = parsedURL.query if self._path == '': self._path = '/' # fix the body if it is in dict format if isinstance(self.body,dict): self.body = urllib.urlencode(self.body) # set other necessary parameters self.targetName = parsedURL.netloc self.targetPort = parsedURL.port self.targetProtocol = (parsedURL.scheme).lower() if self.targetProtocol == 'https': self.isSSL = True if self.targetPort == None: self.targetPort = 443 elif self.targetPort == None: self.targetPort = 80
Example #17
Source File: krasfs.py From tdw with GNU General Public License v3.0 | 6 votes |
def upd(category, sort, str): post = urllib.urlencode({'checkbox_ftp':'on', 'checkbox_tor':'on','word':str}) request = urllib2.Request('http://krasfs.ru/search.php?key=newkey')#url, post) request.add_header('User-Agent', 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; .NET4.0C)') request.add_header('Host', 'www.krasfs.ru') request.add_header('Accept', '*/*') request.add_header('Accept-Language', 'ru-RU') request.add_header('Referer', 'http://www.krasfs.ru') try: f = urllib2.urlopen(request) html = f.read() html = html.replace(chr(10),"") n=html.find("<newkey>") k=html.find("</newkey>") key = html[n+8:k] except IOError, e: if hasattr(e, 'reason'): print 'We failed to reach a server. Reason: '+ e.reason elif hasattr(e, 'code'): print 'The server couldn\'t fulfill the request. Error code: '+ e.code key = "59165b78-bf91-11e1-86bf-c6ab051766ba"
Example #18
Source File: web_request_socket.py From httpninja with Apache License 2.0 | 6 votes |
def _setParams(self): parsedURL = urlparse.urlparse(self.url) # setting the path if self.useAbsolutePath == True: self._path = self.url else: self._path = parsedURL.path self.qs = parsedURL.query if self._path == '': self._path = '/' # fix the body if it is in dict format if isinstance(self.body,dict): self.body = urllib.urlencode(self.body) # set other necessary parameters self.targetName = parsedURL.hostname self.targetPort = parsedURL.port self.targetProtocol = (parsedURL.scheme).lower() if self.targetProtocol == 'https': self.isSSL = True if self.targetPort == None: self.targetPort = 443 elif self.targetPort == None: self.targetPort = 80
Example #19
Source File: cartodb.py From qgis-cartodb with GNU General Public License v2.0 | 6 votes |
def __init__(self, key, secret, email, password, cartodb_domain, host='carto.com', protocol='https', proxy_info=None, *args, **kwargs): super(CartoDBOAuth, self).__init__(cartodb_domain, host, protocol, *args, **kwargs) self.consumer_key = key self.consumer_secret = secret consumer = oauth.Consumer(self.consumer_key, self.consumer_secret) client = oauth.Client(consumer, proxy_info=proxy_info) client.set_signature_method = oauth.SignatureMethod_HMAC_SHA1() params = {} params["x_auth_username"] = email params["x_auth_password"] = password params["x_auth_mode"] = 'client_auth' # Get Access Token access_token_url = ACCESS_TOKEN_URL % {'user': cartodb_domain, 'domain': host, 'protocol': protocol} resp, token = client.request(access_token_url, method="POST", body=urllib.urlencode(params)) access_token = dict(urlparse.parse_qsl(token)) token = oauth.Token(access_token['oauth_token'], access_token['oauth_token_secret']) # prepare client self.client = oauth.Client(consumer, token)
Example #20
Source File: api.py From plugin.video.emby with GNU General Public License v3.0 | 6 votes |
def get_artwork(self, item_id, image, tag=None, query=None): ''' Get any type of artwork: Primary, Art, Banner, Logo, Thumb, Disc ''' query = list(query) if query else [] if item_id is None: return "" if tag is not None: query.append(('Tag', tag)) artwork = "%s/emby/Items/%s/Images/%s/0?%s" % (self.server, item_id, image, urllib.urlencode(query)) if not self.verify_ssl: artwork += "|verifypeer=false" return artwork
Example #21
Source File: cartodbapi.py From qgis-cartodb with GNU General Public License v2.0 | 6 votes |
def getUserTables(self, page=1, per_page=20, shared='yes', returnDict=True): self.returnDict = returnDict payload = { 'tag_name': '', 'q': '', 'page': page, 'type': '', 'exclude_shared': 'false', 'per_page': per_page, 'tags': '', 'shared': shared, 'locked': 'false', 'only_liked': 'false', 'order': 'name', 'types': 'table' } url = QUrl(self.apiUrl + "viz?api_key={}&{}".format(self.apiKey, urllib.urlencode(payload))) request = self._getRequest(url) reply = self.manager.get(request) loop = QEventLoop() reply.downloadProgress.connect(self.progressCB) reply.error.connect(self._error) reply.finished.connect(loop.exit) loop.exec_()
Example #22
Source File: generate-google-id-jwt.py From endpoints-tools with Apache License 2.0 | 6 votes |
def main(args): """Request a Google ID token using a JWT.""" params = urllib.urlencode({ 'grant_type': 'urn:ietf:params:oauth:grant-type:jwt-bearer', 'assertion': generate_jwt(args)}) headers = {"Content-Type": "application/x-www-form-urlencoded"} conn = httplib.HTTPSConnection("www.googleapis.com") conn.request("POST", "/oauth2/v4/token", params, headers) res = json.loads(conn.getresponse().read()) conn.close() return res['id_token']
Example #23
Source File: default.py From plugin.video.emby with GNU General Public License v3.0 | 6 votes |
def browse_subfolders(media, view_id, server_id=None): ''' Display submenus for emby views. ''' from views import DYNNODES get_server(server_id) view = EMBY['api'].get_item(view_id) xbmcplugin.setPluginCategory(int(sys.argv[1]), view['Name']) nodes = DYNNODES[media] for node in nodes: params = { 'id': view_id, 'mode': "browse", 'type': media, 'folder': view_id if node[0] == 'all' else node[0], 'server': server_id } path = "%s?%s" % ("plugin://plugin.video.emby/", urllib.urlencode(params)) directory(node[1] or view['Name'], path) xbmcplugin.setContent(int(sys.argv[1]), 'files') xbmcplugin.endOfDirectory(int(sys.argv[1]))
Example #24
Source File: wfapi.py From terraform-templates with Apache License 2.0 | 6 votes |
def pcap(self, hash=None, platform=None): self.__clear_response() request_uri = '/publicapi/get/pcap' query = {} query['apikey'] = self.api_key if hash is not None: query['hash'] = hash if platform is not None: query['platform'] = platform response = self.__api_request(request_uri=request_uri, body=urlencode(query)) if not response: raise PanWFapiError(self._msg) if not self.__set_response(response): raise PanWFapiError(self._msg)
Example #25
Source File: wfapi.py From terraform-templates with Apache License 2.0 | 6 votes |
def sample(self, hash=None): self.__clear_response() request_uri = '/publicapi/get/sample' query = {} query['apikey'] = self.api_key if hash is not None: query['hash'] = hash response = self.__api_request(request_uri=request_uri, body=urlencode(query)) if not response: raise PanWFapiError(self._msg) if not self.__set_response(response): raise PanWFapiError(self._msg)
Example #26
Source File: wfapi.py From terraform-templates with Apache License 2.0 | 6 votes |
def verdicts_changed(self, date=None): self.__clear_response() request_uri = '/publicapi/get/verdicts/changed' query = {} query['apikey'] = self.api_key if date is not None: query['date'] = date response = self.__api_request(request_uri=request_uri, body=urlencode(query)) if not response: raise PanWFapiError(self._msg) if not self.__set_response(response): raise PanWFapiError(self._msg)
Example #27
Source File: bitly.py From hackernewsbot with MIT License | 6 votes |
def call_method(method, data): data.update({'access_token': TOKEN}) data = urllib.urlencode(data) try: result = urlfetch.fetch( BASE_URL.format(method=method, qs=data), method=urlfetch.GET, deadline=10) except DeadlineExceededError as e: logging.exception(e) return None if result.status_code == 200: return json.loads(result.content).get('data') else: logging.error(result.content) return None
Example #28
Source File: wfapi.py From terraform-templates with Apache License 2.0 | 6 votes |
def verdict(self, hash=None): self.__clear_response() request_uri = '/publicapi/get/verdict' query = {} query['apikey'] = self.api_key if hash is not None: query['hash'] = hash response = self.__api_request(request_uri=request_uri, body=urlencode(query)) if not response: raise PanWFapiError(self._msg) if not self.__set_response(response): raise PanWFapiError(self._msg)
Example #29
Source File: wfapi.py From terraform-templates with Apache License 2.0 | 6 votes |
def report(self, hash=None, format=None): self.__clear_response() request_uri = '/publicapi/get/report' query = {} query['apikey'] = self.api_key if hash is not None: query['hash'] = hash if format is not None: query['format'] = format response = self.__api_request(request_uri=request_uri, body=urlencode(query)) if not response: raise PanWFapiError(self._msg) if not self.__set_response(response): raise PanWFapiError(self._msg)
Example #30
Source File: magnet.py From plugin.video.kmediatorrent with GNU General Public License v3.0 | 6 votes |
def from_torrent_url(url): import base64 import bencode import hashlib import urllib from kmediatorrent.utils import url_get torrent_data = url_get(url) metadata = bencode.bdecode(torrent_data) hashcontents = bencode.bencode(metadata['info']) digest = hashlib.sha1(hashcontents).digest() b32hash = base64.b32encode(digest) params = { 'dn': metadata['info']['name'], 'tr': metadata['announce'], } plugin.log.info(params) paramstr = urllib.urlencode(params) return 'magnet:?%s&%s' % ('xt=urn:btih:%s' % b32hash, paramstr)