def _make_request(self, method, params, data=None, request_method='GET', url=None, content_type='application/json'): if not url: url = '/%s?%s' %( self._create_path(method), urllib2.urlencode(params) ) if data and not isinstance(data, str): data = urllib2.urlencode(data) headers = {'Content-Type': content_type} client.request(request_method, url, data, headers) result = client.getresponse() if result.status < 400: body = result.read() client.close() if body: return self._prepare_response(result.status, simplejson.loads(body)) else: return self._prepare_response(result.status, {}) else: client.close() self._http_error(result.status, result.reason, url ) return self._prepare_response(result.status, {})
def _getPostData(self): if self._data is None: return None if type(self._data) is type(u""): return self._data.encode("utf8") if type(self._data) is type(""): return self._data s = [] for key in self._data: s.append( urllib2.urlencode(u(key).encode("utf8")) + "=" + urllib2.urlencode(u(self._data[key]).encode("utf8")) ) return "&".join(s)
def buftransform(buf, fmt): buf = buf.getvalue() if fmt == 'j': buf = jsonify(buf) elif fmt == 'u': buf = urlencode(buf) elif fmt == 'x': buf = urlencode(buf).replace('%', '\\x') else: raise KeyError('Unsupported buffer transform', fmt) buf = io.BytesIO(buf) buf.seek(0, io.SEEK_END) return buf
def post(url, param): true_param = urllib2.urlencode(param) req = urllib2.Request(url=url, data=true_param) print('request post url:', req) res_data = urllib2.urlopen(req) res = res_data.read() return res
def disambiguate(self, text, lang, key, anntype=None, annres=None, th=None, match=None, mcs=None, dens=None, cands=None, postag=None, extaida=None): values = [ text, lang, key, anntype, annres, th, match, mcs, dens, cands, postag, extaida ] query = urllib2.urlencode({ param: value for param, value in zip(self.PARAMETERS, values) if value is not None }) print query json_string = urllib2.urlopen(self.API + self.DISAMBIGUATE + query).read() #print json_string babelfy_jsons = json.loads(json_string) return [ SemanticAnnotation(babelfy_json) for babelfy_json in babelfy_jsons ]
def deepPlayerSearch(name): url = ( "http://www.mlb.com/lookup/json/named.search_player_all.bam?sport_code='mlb'&name_part='%s%%25'&active_sw='Y'" % urllib2.urlencode(name.upper()) ) try: file = urllib2.urlopen(url) except urllib2.HTTPError: return False results = json.load(file)["search_player_all"]["query_results"] if int(results["totalSize"]) == 1: player = results["row"] # Should probably figure out how to get their jersey number db.execute( "INSERT OR IGNORE INTO players (mlb_id, first, last, num, team) VALUES (?, ?, ?, ?, ?)", (player["player_id"], player["name_first"], player["name_last"], 0, player["team_abbrev"]), ) return getPlayer(player["player_id"]) return False
def _do_http(self, req_dict): req_dict['username'] = self.username req_dict['password'] = self.password data_encoded = urllib2.urlencode(data) response = urllib2.urlopen(self.url, data_encoded) return response.read().split('\n')
def gsearch(searchfor): query = urllib.urlencode({'q': searchfor}) url = 'http://ajax.googleapis.com/ajax/services/search/web?v=1.0&%s' % query search_response = urllib.urlopen(url) search_results = search_response.read() results = json.loads(search_results) data = results['responseData'] return data
def browseMaps(self): """ Brings up a web browser with the address in a Google map. """ url = self.urlTemplate() params = urllib.urlencode({self.urlQueryKey(): self.location()}) url = url % {'params': params} webbrowser.open(url)
def post(url, values): try: data = urllib2.urlencode(values) req = urllib2.Request(url, data) response = urllib2.urlopen(req) return response.read() except urllib2.URLError, e: print("Url Error:", str(e)) return None
def kw_post(self, *a, **kw): """ Internal function: Sends encoded data to an url """ if len(a) <> 1: raise TypeError, "kw_post takes exactly 1 argument (%s given)" % len(a) u = urllib2.urlopen(a[0], data=urllib2.urlencode(kw)) d = u.read() u.close() return d
def browseMaps( self ): """ Brings up a web browser with the address in a Google map. """ url = self.urlTemplate() params = urllib.urlencode({self.urlQueryKey(): self.location()}) url = url % {'params': params} webbrowser.open(url)
def request(method, url, data): data = urllib2.urlencode(post_data) try: c = urllib2.Request(url, data, headers) c.request(method, url, data, headers) c.close() except Exception as e: print(e) raise return(urllib2.urlopen(c).read())
def http_request_post(self, httpReq, params): try: p = urllib2.urlencode(params) sock = urllib2.urlopen(httpReq, p, timeout=self.timeout) ret = json.loads(sock.read()) return sock.getcode(), ret except Exception, e: errInfo = traceback.format_exc() printlog('Error', 'SendHttp_error', errInfo) return 500, None
def kw_post(self, *a, **kw): """ Internal function: Sends encoded data to an url """ if len(a) <> 1: raise TypeError, 'kw_post takes exactly 1 argument (%s given)' % len( a) u = urllib2.urlopen(a[0], data=urllib2.urlencode(kw)) d = u.read() u.close() return d
def post(self): token = self.request.get("token") ipn_address = "https://sandbox.alertpay.com/sandbox/IPN2.ashx" raw_post_data = {"token": token} post_data = urllib2.urlencode(raw_post_data) request = urllib2.Request(ipn_address, post_data) response = urllib2.urlopen(request) response_text = response.read() print response_text
def post(uri, query): """ Execute an HTTP POST query. `uri` is the target URI, and `query` is the POST data. """ if not uri.startswith('http'): return data = urllib2.urlencode(query) u = urllib2.urlopen(uri, data) bytes = u.read() u.close() return bytes
def catJustAte(request, amount,timeStart,timeEnd,YYYYMMDD): urltopost="http://healthcat.herokuapp.com/record" data= urllib2.urlencode({'amount':amount, 'tStart':timeStart, 'tEnd':timeEnd, 'YYYYMMDD':YYYYMMDD}) conn= httplib.HTTPConnection(urltopost) headers = {"content_type": "application/x-www-form-urlencoded", "Accept":"text/plain"} conn.request('POST','/record',data,headers) response= conn.getresponse() pass
def authenticate(self, request): user = self.clean(request.POST['username']) password = self.clean(request.POST['password']) params = urllib2.urlencode({'username': user, 'password': password}) resp = urllib2.urlopen(self.auth_url, params) data = resp.read() if self.validate_login(data): self.set_session(request) return True else: return False
def post_pin(access_token, board, note, link, image_url): response = urllib2.urlopen('https://api.pinterest.com/v1/pins/', data=urllib2.urlencode( dict( access_token=access_token, board=board, note=note, link=link, image_url=image_url, ))) response_data = json.load(response) return response_data
def request(self, path, args=None, post_args=None): """Fetches the given path in the Graph API. We translate args to a valid query string. If post_args is given, we send a POST request to the given path with the given arguments. """ if not args: args = {} if self.access_token: if post_args is not None: post_args["access_token"] = self.access_token else: args["access_token"] = self.access_token post_data = None if post_args is None else urllib2.urlencode(post_args) file = urllib.urlopen("https://graph.facebook.com/" + path + "?" + urllib2.urlencode(args), post_data) try: response = _parse_json(file.read()) finally: file.close() if response.get("error"): raise GraphAPIError(response["error"]["type"], response["error"]["message"]) return response
def Report(self, *evnt): if self.email.IsChecked(): email = self.ValidateEmail() else: email = None url = 'http://www.suever.net/software/dicomSort/bug_report.php' values = {'OS': sys.platform, 'version': __version__, 'email': email, 'comments': self.comments.GetValue().strip('\n')} data = urllib2.urlencode(values) urllib2.urlopen(url, data) self.OnCancel()
def verify(ip, challange, response): payload = {} payload['privatekey'] = privkey.encode('utf-8') payload['remoteip'] = ip.encode('utf-8') payload['challenge'] = challange.encode('utf-8') payload['response'] = response.encode('utf-8') payload = urllib2.urlencode(payload) result_req = urllib2.Request(url="http://www.google.com/recaptcha/api/verify", data=payload, headers={'Content-Type': 'application/x-www-form-urlencoded'}) result = urllib2.urlopen(result_req).read() if result.status_code == 200: return result.content.startswith("true") # if not 20OK or not starting with true we have a problem return False
def update_sickgear(self, media_id, path_file, play_count, profile): self.notify('Update sent to SickGear') url = 'http://%s:%s/update-watched-state-kodi/' % ( self.addon.getSetting('sickgear_ip'), self.addon.getSetting('sickgear_port')) self.log('Notify state to %s with path_file=%s' % (url, path_file)) msg_bad = 'Failed to contact SickGear on port %s at %s' % ( self.addon.getSetting('sickgear_port'), self.addon.getSetting('sickgear_ip')) payload_json = self.payload_prep( dict(media_id=media_id, path_file=path_file, played=play_count, label=profile)) if payload_json: payload = urlencode(dict(payload=payload_json)) try: rq = Request(url, data=payload) r = urlopen(rq) response = json.load(r) r.close() if 'OK' == r.msg: self.payload_prep(response) if not all(itervalues(response)): msg = 'Success, watched state updated' else: msg = 'Success, %s/%s watched stated updated' % (len([ v for v in itervalues(response) if v ]), len(itervalues(response))) self.log(msg) self.notify(msg, error=False) else: msg_bad = 'Failed to update watched state' self.log(msg_bad) self.notify(msg_bad, error=True) except (URLError, IOError) as e: self.log(u'Couldn\'t contact SickGear %s' % self.ex(e), error=True) self.notify(msg_bad, error=True, period=15) except (BaseException, Exception) as e: self.log(u'Couldn\'t contact SickGear %s' % self.ex(e), error=True) self.notify(msg_bad, error=True, period=15)
def verify(ip, challange, response): payload = {} payload['privatekey'] = privkey.encode('utf-8') payload['remoteip'] = ip.encode('utf-8') payload['challenge'] = challange.encode('utf-8') payload['response'] = response.encode('utf-8') payload = urllib2.urlencode(payload) result_req = urllib2.Request( url="http://www.google.com/recaptcha/api/verify", data=payload, headers={'Content-Type': 'application/x-www-form-urlencoded'}) result = urllib2.urlopen(result_req).read() if result.status_code == 200: return result.content.startswith("true") # if not 20OK or not starting with true we have a problem return False
def http_delete(host, path, delete_data, header_map={}, parameters_map=None): """ Sends a HTTP DELETE request and returns the response Raises exception if HTTP 200 is not received in response :param host: host address :param path: path in URL :param data: post data in message :param post_data: HTTP request headers to send in GET request e.g. http_get("http://www.apple.com/", "robots.txt", {"User-Agent": "Safari"}) """ class RequestWithMethod(urllib2.Request): def __init__(self, method, *args, **kwargs): self._method = method urllib2.Request.__init__(self, *args, **kwargs) def get_method(self): return self._method request_url = host + path if parameters_map: param_data = urllib2.urlencode(parameters_map) request_url = request_url + "?" + param_data request = RequestWithMethod("DELETE", url=request_url, data=delete_data, headers=header_map) try: response = urllib2.urlopen(request) except HTTPError as error: print("HTTP response error") print(error.read()) raise error return response.read()
def query_google_for_names(address, key='AIzaSyBDUwLqoWAiAS4sTfFccdaz583W060jbok'): py3 = sys.version_info >= (3, 0) url = 'https://www.googleapis.com/civicinfo/v2/representatives' payload = { 'address': address, 'includeOffices': 'True', 'levels': 'country', 'key': key } if py3: import urllib.parse import urllib.request data = urllib.parse.urlencode(payload) req = url + '?' + data with urllib.request.urlopen(req) as response: output = json.loads(response.read().decode('ascii')) else: import urllib2 data = urllib2.urlencode(payload) req = url + '?' + data with urllib2.urlopen(req) as response: output = json.loads(response.read().decode('ascii')) officials_list = [ContactInfo.from_google(j) for j in output['officials']] moc_list = [official for official in officials_list if official.is_MoC] name_list = [moc.name for moc in moc_list] return name_list
def http_request(host, path, post_data=None, header_map={}, parameters_map={}): request_url = host + path if parameters_map: param_data = urllib2.urlencode(parameters_map) request_url = request_url + "?" + param_data print "Request : " + request_url request = urllib2.Request(url=request_url, data=post_data, headers=header_map) try: response = "" response = urllib2.urlopen(request) # Raise exception if the network request has failed if response.code is not 200: print response.read() raise except HTTPError as error: print error.read() raise error return response.read()
def post(self): logging.info('Beginning new Pledge POST...') """ Submit and process submitted pledges. """ form = PledgeLanding(self.request) try: logging.debug('Beginning validation...') if form.validate(): logging.debug('Validation passed.') u_key = str(form.u_key.data).strip('=') u_fbid = str(form.u_fbid.data).strip('=') action = str(form.u_action.data) u_next_action = str(form.u_nextAction.data) u_prev_action = str(form.u_prevAction.data) firstname = str(form.firstname.data) lastname = str(form.lastname.data) email = str(form.email.data) phone = str(form.phone.data) message = str(form.message.data) logging.info('Submitted form POST data follows...') logging.info('action = '+action) logging.info('next = '+u_next_action) logging.info('prev = '+u_prev_action) logging.info('key = '+u_key) logging.info('firstname = '+firstname) logging.info('lastname = '+lastname) logging.info('email = '+email) logging.info('phone = '+phone) logging.info('message = '+message) if action is not False: logging.debug('Action valid.') if u_key is not False: ## Use Key or FBID, whichever exists if u_key == '' or u_key is None: if u_fbid == '' or u_key is None: abort(400) logging.error('Request failed because both fbid and key are missing.') return Response('<b>Must provide FBID or U_KEY.') else: logging.info('Using FBID to identify user.') u = FacebookUser.get_by_key_name(u_fbid) else: logging.info('Using KEY to identify user.') u = db.get(db.Key(u_key)) logging.info('User record: '+str(u)) u.firstname = firstname u.lastname = lastname u.email = email u.phone = phone u.has_pledged = True p = Pledge(u, user=u, personal_message=message) db.put([u, p]) logging.debug('Put pledge and updated user.') if u_next_action is not False: logging.debug('Redirecting to next action...') return redirect(u_next_action) else: logging.error('Couldn\'t retrieve key. Exiting 404.') abort(404) else: logging.error('Missing action. Exiting 400.') abort(400) except ValidationError, e: logging.error('Form validation failed. Redirecting with error text.') self.redirect(self.request.headers.get('referrer')+'&validationError=true&error='+urllib2.urlencode(str(e.message)))
def crRequest(doi): import urllib as U data = {'q': doi} data_encoded = U.urlencode(data) return _json_request('http://search.labs.crossref.org/dois?%s' % data_encoded)
def post(self): logging.info('Beginning new outgoing email POST...') form = EmailInvites(self.request) try: logging.debug('Beginning validation...') if form.validate(): logging.debug('Validation passed.') u_key = str(form.u_key.data).strip('=') u_fbid = str(form.u_fbid.data).strip('=') message = str(form.message.data) email_1 = str(form.email_1.data) email_2 = str(form.email_2.data) email_3 = str(form.email_3.data) email_4 = str(form.email_4.data) email_5 = str(form.email_5.data) logging.info('Submitted form POST data follows...') logging.info('key = '+u_key) logging.info('email 1 = '+email_1) logging.info('email 2 = '+email_2) logging.info('email 3 = '+email_3) logging.info('email 4 = '+email_4) logging.info('email 5 = '+email_5) logging.info('message = '+message) emails = [email_1, email_2, email_3, email_4, email_5] if u_key is not False: ## Use Key or FBID, whichever exists if u_key == '' or u_key is None: if u_fbid == '' or u_key is None: abort(400) logging.error('Request failed because both fbid and key are missing.') return Response('<b>Must provide FBID or U_KEY.') else: logging.info('Using FBID to identify user.') u = FacebookUser.get_by_key_name(u_fbid) else: logging.info('Using KEY to identify user.') u = db.get(db.Key(u_key)) logging.info('User record: '+str(u)) if message == '' or message is None: message = 'Sign up for YVR today! (DEVTEST)' tickets = [] for email in emails: if mail.is_email_valid(email): tickets.append(OutboundEmail(user=u, to_email=email, subject='(DEV) YV Outbound Email', message=message)) keys = db.put(tickets) tasks = [] for item in keys: t = taskqueue.Task(url='/_api/mail/send', params={'ticket':str(item)}).add(queue_name='outbound-mail') else: logging.error('Couldn\'t retrieve key. Exiting 404.') abort(404) except ValidationError, e: logging.error('Form validation failed. Redirecting with error text.') self.redirect(self.request.headers.get('referrer')+'&validationError=true&error='+urllib2.urlencode(str(e.message)))
def get_url(_url, **kwargs): return "{0}?{1}".format(_url, urllib.urlencode(kwargs))
def post(self): logging.info('Beginning new Pledge POST...') """ Submit and process submitted pledges. """ form = PledgeLanding(self.request) try: logging.debug('Beginning validation...') if form.validate(): logging.debug('Validation passed.') u_key = str(form.u_key.data).strip('=') u_fbid = str(form.u_fbid.data).strip('=') u_next_action = str(form.u_nextAction.data) u_lists = form.u_lists.data u_prev_action = str(form.u_prevAction.data) firstname = str(form.firstname.data) lastname = str(form.lastname.data) email = str(form.email.data) phone = str(form.phone.data) zipcode = str(form.zipcode.data) message = str(form.message.data) logging.info('Submitted form POST data follows...') logging.info('next = '+u_next_action) logging.info('lists = '+str(u_lists)) logging.info('prev = '+u_prev_action) logging.info('key = '+u_key) logging.info('firstname = '+firstname) logging.info('lastname = '+lastname) logging.info('email = '+email) logging.info('phone = '+phone) logging.info('zipcode = '+zipcode) logging.info('message = '+message) logging.debug('Action valid.') ## Use Key or FBID, whichever exists if u_key == '' or u_key is None: if u_fbid == '' or u_key is None: logging.info('Creating anonymous microsite user.') u = MicrositeUser() else: logging.info('Using FBID to identify user.') u = FacebookUser.get_by_key_name(u_fbid) else: logging.info('Using KEY to identify user.') u = db.get(db.Key(u_key)) logging.info('User record: '+str(u)) u.firstname = firstname u.lastname = lastname u.email = email u.phone = phone u.zipcode = int(zipcode) u.has_pledged = True if not u.is_saved(): u.put() memberships = [] if isinstance(u_lists, list) and len(u_lists) > 0: for list_item in u_lists: memberships.append(ListMember(user=u, list=db.Key(list_item), opted_in=True)) p = Pledge(u, user=u, personal_message=message) db.put([u, p]+memberships) logging.debug('Put pledge, updated user, and list memberships.') if u_next_action is not False: logging.debug('Redirecting to next action...') return redirect(u_next_action) except ValidationError, e: logging.error('Form validation failed. Redirecting with error text.') self.redirect(self.request.headers.get('referrer')+'&validationError=true&error='+urllib2.urlencode(str(e.message)))
import urllib2 url = 'https://api.ordnancesurvey.co.uk/places/v1/addresses/uprn?%s' params = urllib2.urlencode({'uprn':200010019924,'dataset':'DPA,LPI', 'key':'INSERT_YOUR_API_KEY_HERE'}) try: f = urllib2.urlopen(url % params) except Exception as e: print(str(e)) response=f.read() #print 'RESPONSE:', response for line in response.splitlines(): word_lst = line.split(':') for word in word_lst: if '"ADDRESS" ' in word: print(line) if 'COORDINATE' in word: print(line) if 'UPRN' in word: print(line) f.close()
def proxy(request): logger.error("Error may start here") logger.error(request) server = request.META["HTTP_HOST"] path = request.get_full_path() # parse hostname and port hostname, port = parse_host_port(server) full_host = request.get_host() #parse out the headers that are relevant to pass onto the end server request_headers = {} for h in ["Cookie", "Referer", "X-Csrf-Token"]: if h in request.META.items(): request_headers[h] = request.headers[h] if request.method == "POST": form_data = list(iterform(request.POST)) form_data = urllib2.urlencode(form_data) request_header["Content-Length"] = len(form_data) else: form_data = None url = request.build_absolute_uri() # get response and content from original destination h = httplib2.Http() resp, content = h.request(url, request.method, body = form_data, headers = request_headers) #print resp # need to figure out how to modify the headers #response_headers = Headers() #for key, value in resp.getheaders(): # if key in ["content-length", 'connection', 'content-type']: # continue # # if key == 'set-cookie': # cookies = value.split(',') # [response_headers.add(key, c) for c in cookies] # else: # response_headers.add(key, value) # don't really know what to do in case of redirect, should test this out # if 'location' in response_headers: # redirect = response_headers['location'] # parsed= urlparse.urlparse() # process content in two stages #first change resource urls to absolute urls #root = url_for (".proxy_request", host = full_host) #urlparse.urljoin(url, link) #print content # construct the response object from the template #head, body, data = type = survey head, pre, post = clean_and_split(content) response = render(request, 'mysite/output.html', ({"url": url, "head" : head, "pre": pre, "post": post})) #response = render(request, 'mysite/output.html', ({})) # modify response headers here # return response to client return response
def makeNewStudent(ID): try: html = urllib2.urlopen(urllib2.Request("https://palo-alto.edu/Forgot/Reset.cfm",urllib2.urlencode({"username":str(ID)}))) name = re.search(r'<input name="name" type="hidden" label="name" value=(.*?)"',html).group(0) Student(name=name,studentID=ID,subteam=Subteam.objects.filter(name="Unknown")).save() return True except: return False
import urllib2 url = 'https://api.ordnancesurvey.co.uk/places/v1/addresses/uprn?%s' params = urllib2.urlencode({ 'uprn': 200010019924, 'dataset': 'DPA,LPI', 'key': 'INSERT_YOUR_API_KEY_HERE' }) try: f = urllib2.urlopen(url % params) except Exception as e: print(str(e)) response = f.read() #print 'RESPONSE:', response for line in response.splitlines(): word_lst = line.split(':') for word in word_lst: if '"ADDRESS" ' in word: print(line) if 'COORDINATE' in word: print(line) if 'UPRN' in word: print(line) f.close()
import urllib2 url = 'http://pythonprogramming.net' values = {'s': 'basic', 'submit': 'search'} data = urllib2.urlencode(values) data = data.encode('utf-8') req = urllib2.Request(url, data) resp = urllib2.urlopen(req) respData = resp.read() print(respData)
'Accept-Language': "en-US,en;q=0.5", \ 'Referer': "http://54.221.6.249/level3.php", \ 'Cookie': "0", \ 'Connection': "keep-alive", \ 'Upgrade-Insecure-Requests': "1"} post_data = {\ 'id': 53, \ 'key': 0, \ 'holdthedoor': "Submit", \ 'captcha': 0} url = "http://54.221.6.249/level3.php" def request(method, url, data): data = urllib2.urlencode(post_data) try: c = urllib2.Request(url, data, headers) c.request(method, url, data, headers) c.close() except Exception as e: print(e) raise return(urllib2.urlopen(c).read()) if __name__ == "__main__": try: data = None get = request("GET", url, data) data = urllib2.urlencode(post_data)
import urllib2 import json serviceurl = 'http://python-data.dr-chuck.net/geojson?' place = "Nagpur University" url = serviceurl + urllib2.urlencode({'sensor':'false', 'address': place}) data = urllib2.urlopen(url).read() js = json.loads(data) print "Place id", js['results'][0]['place_id']
import urllib2 # Put the port the server is running here. url = "http://localhost:8080" requestBody = { "name": "Victor Anyirah", "userhandler": "Coldsoldier", "garbage": 1232132, "user_id": "12321", "postCount": 0, } data = urllib2.urlencode(requestBody) request = urlib2.Request(url, data) response = urllib2.urlopen(request) print response.geturl() print response.info() the_page = response.read() print the_page
"da_par": "direct", "pcevaname": "pc4.1", "qt": "con", "c": 332, # 城市代码 "wd": '商场', # 搜索关键词 "wd2": "", "pn": 0, # 页数 "nn": 0, "db": "0", "sug": "0", "addr": "0", "da_src": "pcmappg.poi.page", "on_gel": "1", "src": "7", "gr": "3", "l": "12", "tn": "B_NORMAL_MAP", # "u_loc": "12621219.536556,2630747.285024", "ie": "utf-8", # "b": "(11845157.18,3047692.2;11922085.18,3073932.2)", #这个应该是地理位置坐标,可以忽略 "t": "1468896652886" } uri = 'http://map.baidu.com/' parameter = urllib2.urlencode(parameter) print parameter ret = urllib.urlopen("%s?%s" % (uri, parameter)) code = ret.getcode() ret_data = ret.read() print ret_data
import urllib2 data = {'name': 'pdffile', 'file': open('test.pdf') } edata = urllib2.urlencode(data) urllib2.urlopen('http://localhost:8000/', edata)
def doMainJob(): sysInfo = SYSINFO.generateInfo() postData = {} postData['sysinfo'] = sysInfo result = getHTTPPost(CONFIG_SERVERURL,urllib2.urlencode(postData)) print result
'type': 'tweet', 'window': 'a', 'perpage': '100' } # http://code.google.com/p/otterapi/wiki/Resources if options.unique: params['nohidden'] = '0' searchurl = "http://otter.topsy.com/search.json?" c = connection.Connection() db = c.topsy def store(otterdata): if verbose: print otterdata['content'], otterdata['url'], otterdata[ 'trackback_total'] db.rawtopsy.save(otterdata) count = 1 while count <= 10: queryurl = searchurl + urlencode(params) + '&page=' + str(count) if verbose: print "* * * fetching ", queryurl data = urlopen(queryurl) resp = json.loads(data.read()) if resp: for r in resp['response']['list']: store(r) count += 1 sleep(options.interval)
import urllib import urllib2 words = [] with open("words.txt", "r") as f: words = [x.replace("\n", "") for x in f.readlines()] post_params = {"user_input": "adv"} post_args = urllib2.urlencode(post_params) url = 'https://eventmobi.com/cwsf-espc/game/209225/challenges' fp = urllib2.urlopen(url, post_args)
def urlEncode(content): return urllib2.urlencode(content)