本文整理汇总了Python中restkit.request函数的典型用法代码示例。如果您正苦于以下问题:Python request函数的具体用法?Python request怎么用?Python request使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了request函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: ping
def ping(self, issue, command, created, creator):
"""
note: we might send multiple pings if a command was of more than one class
"""
for row in self.graph.queryd(
"SELECT DISTINCT ?cls WHERE { ?cmd a ?cls }",
initBindings={'cmd' : command}):
payload = jsonlib.write({
'issue' : issue,
'commandClass' : row['cls'],
'command' : command,
'created' : created,
'creator' : creator,
})
for receiver in [
"http://bang:9030/dispatch/newCommand",
# ^ this one should be dispatching to the rest, but i
# don't have a proper PSHB setup yet
"http://bang:9055/newCommand",
"http://bang:9072/newCommand",
]:
try:
restkit.request(
method="POST", url=receiver,
body=payload,
headers={"Content-Type" : "application/json"})
except Exception, e:
log.error(e)
开发者ID:drewp,项目名称:magma,代码行数:29,代码来源:db.py
示例2: postIdenticaOauth
def postIdenticaOauth():
""" not working yet. last tried on 2010-05 """
from restkit import OAuthFilter, request
import restkit.oauth2
consumer = restkit.oauth2.Consumer(key=oauthKey, secret=oauthSecret)
request_token_url = "http://identi.ca/api/oauth/request_token"
auth = OAuthFilter(('*', consumer))
if 1:
# The request.
resp = request(request_token_url, filters=[auth])
print resp.__dict__
print resp.body_string()
else:
tok = restkit.oauth2.Token(oauth_token, oauth_token_secret)
resp = restkit.request(
"http://identi.ca/api/statuses/friends_timeline.json",
filters=[OAuthFilter(('*', consumer, tok))],
method="GET")
print resp.body_string()
print resp
resp = restkit.request("http://identi.ca/api/statuses/update.json",
filters=[OAuthFilter(('*', consumer, tok))],
method="POST",
body=jsonlib.dumps({'status' : 'first oauth update'}))
print resp.body_string()
print resp
开发者ID:drewp,项目名称:magma,代码行数:33,代码来源:microblog.py
示例3: test_003
def test_003():
u = "http://test:[email protected]%s:%s/auth" % (HOST, PORT)
r = request(u)
t.eq(r.status_int, 200)
u = "http://test:[email protected]%s:%s/auth" % (HOST, PORT)
r = request(u)
t.eq(r.status_int, 403)
开发者ID:pashinin,项目名称:restkit,代码行数:7,代码来源:008-tst-request.py
示例4: attach_img
def attach_img(db, tweet, url, attname):
res = restkit.request(url)
if res.status_int == 200:
# convert image in PNG
img = Image.open(BytesIO(res.body_string()))
out = BytesIO()
img.save(out, 'png')
out.seek(0)
# send to couchdb
db.put_attachment(tweet, out, "%s.png" % attname,
headers={'Transfer-Encoding': 'chunked'})
# create thumbnail if the attachment is a photo
if attname == 'photo':
ratio = 1
if img.size[0] > max_width:
ratio = max_width / float(img.size[0])
elif img.size[1] > max_height:
ratio = max_height / float(img.size[1])
w = img.size[0] * ratio
h = img.size[1] * ratio
thumb = img.resize((int(w), int(h)), Image.ANTIALIAS)
tout = BytesIO()
thumb.save(tout, 'png')
tout.seek(0)
# send it to couchdb
db.put_attachment(tweet, tout, "%s_thumb.png" % attname,
headers={'Transfer-Encoding': 'chunked'})
开发者ID:benoitc,项目名称:foodoverip,代码行数:32,代码来源:grabber.py
示例5: search_twitter
def search_twitter(db, q, since=0, concurrency=10):
base_url = "http://search.twitter.com/search.json"
params = {"q": q, "include_entities": "true", "result_type": "mixed"}
if since > 0:
params.update({"since_id": str(since)})
path = "?" + urllib.urlencode(params)
found = 0
while True:
resp = restkit.request(base_url + path)
with resp.body_stream() as stream:
res = json.load(stream)
results = res.get('results')
found += len(results)
for result in results:
process_tweet(db, result)
if res["page"] == 1 and res['max_id'] != since:
since = res['max_id']
# next page continue, else stop
if "next_page" in res:
path = res["next_page"]
else:
break
return (since, found)
开发者ID:benoitc,项目名称:foodoverip,代码行数:28,代码来源:grabber.py
示例6: test_002
def test_002():
u = "http://%s:%s" % (HOST, PORT)
r = request(u, 'POST', body=LONG_BODY_PART)
t.eq(r.status_int, 200)
body = r.body_string()
t.eq(len(body), len(LONG_BODY_PART))
t.eq(body, LONG_BODY_PART)
开发者ID:pashinin,项目名称:restkit,代码行数:7,代码来源:008-tst-request.py
示例7: _doRequest
def _doRequest(self, action, method, body=None, headers=None):
url = urlparse.urljoin(self.uriBase, self.uriPath + '/' + action)
log.debug("URL via (%s): %s" % (method, url))
if headers is None:
headers = {}
headers['User-Agent'] = '@[email protected]@[email protected]'
if method in ["GET", "HEAD", "DELETE", "POST", "PUT"]:
response = restkit.request(url, method=method, body=body, headers=headers,
filters=[self.auth])
else:
raise restkit.errors.InvalidRequestMethod("Unsupported Method")
if response.status_int >= 400:
if response.status_int == 404:
raise restkit.errors.ResourceNotFound(response.body_string())
elif response.status_int == 401:
raise restkit.errors.Unauthorized("Unauthorized Request")
else:
raise restkit.errors.RequestFailed(response.body_string(), response.status_int, response)
# body_string() can only be called once, since it's a socket read, or
# will throw an AlreadyRead exception.
response.body = response.body_string()
return response
开发者ID:stigkj,项目名称:glu,代码行数:29,代码来源:rest.py
示例8: child_sensorsRdf
def child_sensorsRdf(self, ctx):
trig = ""
import restkit
for uri in ["http://bang:9069/graph", "http://bang:9070/graph"]:
trig += restkit.request(uri).body_string()
return trig
开发者ID:drewp,项目名称:magma,代码行数:7,代码来源:homepage.py
示例9: req
def req(url):
if settings.DEBUG:
print url
r = request(url)
if r.status_int not in (200, ):
raise Exception("can't reach url :%s\n%s" % (url, r.status))
return r
开发者ID:Abouplah,项目名称:nefpy,代码行数:7,代码来源:api.py
示例10: readurl
def readurl():
r = request('http://friendpaste.com/1ZSEoJeOarc3ULexzWOk5Y_633433316631/raw')
print "RESULT: %s: %s (%s)" % (u, r.status, len(r.body_string()))
# t = timeit.Timer(stmt=extract)
# print "%.2f s" % t.timeit(number=1)
开发者ID:julytwilight,项目名称:check-msohu,代码行数:7,代码来源:rest.py
示例11: __call__
def __call__(self, environ, start_response):
method = environ['REQUEST_METHOD']
if method not in self.allowed_methods:
start_response('403 Forbidden', ())
return ['']
if self.strip_script_name:
path_info = ''
else:
path_info = environ['SCRIPT_NAME']
path_info += environ['PATH_INFO']
query_string = environ['QUERY_STRING']
if query_string:
path_info += '?' + query_string
host_uri = self.extract_uri(environ)
uri = host_uri+path_info
new_headers = {}
for k, v in environ.items():
if k.startswith('HTTP_'):
k = k[5:].replace('_', '-').title()
new_headers[k] = v
for k, v in (('CONTENT_TYPE', None), ('CONTENT_LENGTH', '0')):
v = environ.get(k, None)
if v is not None:
new_headers[k.replace('_', '-').title()] = v
if new_headers.get('Content-Length', '0') == '-1':
raise ValueError(WEBOB_ERROR)
response = request(uri, method,
body=environ['wsgi.input'], headers=new_headers,
pool_instance=self.pool)
if 'location' in response:
headers = []
for k, v in response.headerslist:
if k == 'Location':
# rewrite location with a relative path. dont want to deal
# with complex url rebuild stuff
if v.startswith(host_uri):
v = v[len(host_uri):]
if self.strip_script_name:
v = environ['SCRIPT_NAME'] + v
headers.append((k, v))
else:
headers = response.headerslist
start_response(response.status, headers)
if 'content-length' in response and \
int(response['content-length']) <= MAX_BODY:
return [response.body]
return ResponseIter(response)
开发者ID:czue,项目名称:restkit,代码行数:58,代码来源:wsgi_proxy.py
示例12: _fetch_data
def _fetch_data(from_date, to_date, page_size=20, first_page=1):
"""Fetch a chunk of vulndb"""
from_date = from_date.strftime("%Y-%m-%d")
to_date = to_date.strftime("%Y-%m-%d")
logger.info("Working on date range: {} - {}".format(from_date, to_date))
consumer = oauth2.Consumer(key=consumer_key, secret=consumer_secret)
# client = oauth2.Client(consumer)
# now get our request token
auth = OAuthFilter('*', consumer)
# initialize the page counter either at the first page or whatever page
# was requested
page_counter = first_page
finished = False
reply = dict()
reply['results'] = []
while not finished:
url = 'https://vulndb.cyberriskanalytics.com' + \
'/api/v1/vulnerabilities/find_by_date?' + \
'start_date=' + from_date + '&end_date=' + to_date + '&page=' + \
str(page_counter) + '&size=' + str(page_size) + \
'&date_type=updated_on' + \
'&nested=true'
logger.debug("Working on url: {} ".format(url))
resp = request(url, filters=[auth])
if resp.status_int == 404:
logger.warning("Could not find anything for the week " +
"begining: {}".format(from_date))
return
if resp.status_int != 200:
raise Exception("Invalid response {}.".format(resp['status']))
logger.debug("\tHTTP Response code: " + str(resp.status_int))
"""parse response and append to working set"""
page_reply = json.loads(resp.body_string())
logger.debug("Retrieving page {} of {}.".format(page_counter,
-(-page_reply['total_entries'] // page_size)))
if len(page_reply['results']) < page_size:
finished = True
reply['results'].extend(page_reply['results'])
reply['total_entries'] = page_reply['total_entries']
else:
page_counter += 1
reply['results'].extend(page_reply['results'])
logger.info("Returning {} out of {} results".format(str(len(
reply['results'])), str(reply['total_entries'])))
return reply
开发者ID:SCH-CISM,项目名称:VulnPryer,代码行数:57,代码来源:vulndb.py
示例13: test_003
def test_003(o, u, b):
r = request(u, "POST", body=b, filters=[o],
headers={"Content-type": "application/x-www-form-urlencoded"})
import sys
print >>sys.stderr, r.body_string()
t.eq(r.status_int, 200)
# Because this is a POST and an application/x-www-form-urlencoded, the OAuth
# can include the OAuth parameters directly into the body of the form, however
# it MUST NOT include the 'oauth_body_hash' parameter in these circumstances.
t.isnotin("oauth_body_hash", r.request.body)
开发者ID:Leits,项目名称:restkit,代码行数:10,代码来源:009-test-oauth_filter.py
示例14: fetchResource
def fetchResource(self, url):
response = restkit.request(url=url,
headers=self.proxyHeaders())
if not response.status.startswith('2'):
raise ValueError("request failed with %r" % response.status)
body = response.body_string()
log.info("got %s byte response, content-type %s", len(body),
response['headers'].get('content-type', None))
return body
开发者ID:drewp,项目名称:httpsnapshot,代码行数:10,代码来源:snapshot.py
示例15: all_roles
def all_roles(self,token_encode,options={}):
try:
gurl = 'https://authz-%s-conjur.herokuapp.com' % (options["stack"])
headers = {"Authorization":token_encode}
url = "/%s/roles/user/%s/?all" % (options["account"],options["username"])
r = request(gurl+url, method='GET', headers=headers)
jsonenv = json.loads(r.body_string())
return jsonenv
except Exception,exc:
print "Error roles: %s" % (exc)
开发者ID:inscitiv,项目名称:api-python,代码行数:10,代码来源:Resource.py
示例16: __call__
def __call__(self, environ, start_response):
method = environ["REQUEST_METHOD"]
if method not in self.allowed_methods:
start_response("403 Forbidden", ())
return [""]
if self.strip_script_name:
path_info = ""
else:
path_info = environ["SCRIPT_NAME"]
path_info += environ["PATH_INFO"]
query_string = environ["QUERY_STRING"]
if query_string:
path_info += "?" + query_string
host_uri = self.extract_uri(environ)
uri = host_uri + path_info
new_headers = {}
for k, v in environ.items():
if k.startswith("HTTP_"):
k = k[5:].replace("_", "-").title()
new_headers[k] = v
for k, v in (("CONTENT_TYPE", None), ("CONTENT_LENGTH", "0")):
v = environ.get(k, None)
if v is not None:
new_headers[k.replace("_", "-").title()] = v
if new_headers.get("Content-Length", "0") == "-1":
raise ValueError(WEBOB_ERROR)
response = request(uri, method, body=environ["wsgi.input"], headers=new_headers, pool_instance=self.pool)
if "location" in response:
headers = []
for k, v in response.headerslist:
if k == "Location":
# rewrite location with a relative path. dont want to deal
# with complex url rebuild stuff
if v.startswith(host_uri):
v = v[len(host_uri) :]
if self.strip_script_name:
v = environ["SCRIPT_NAME"] + v
headers.append((k, v))
else:
headers = response.headerslist
start_response(response.status, headers)
if "content-length" in response and int(response["content-length"]) <= MAX_BODY:
return [response.body]
return ResponseIter(response)
开发者ID:mwhooker,项目名称:restkit,代码行数:55,代码来源:wsgi_proxy.py
示例17: guess_language
def guess_language(text):
if not restkit:
return None
if isinstance(text, unicode):
text = text.encode('utf-8')
url = 'http://www.google.com/uds/GlangDetect?'
url += urllib.urlencode(dict(v='1.0', q=text))
resp = restkit.request(url)
data = resp.body_string()
data = json.loads(data)
return data.get('responseData', {}).get('language', None)
开发者ID:gawel,项目名称:tweeql2solr,代码行数:11,代码来源:utils.py
示例18: test_004
def test_004():
u = "http://%s:%s/multipart2" % (HOST, PORT)
fn = os.path.join(os.path.dirname(__file__), "1M")
f = open(fn, 'rb')
l = int(os.fstat(f.fileno())[6])
b = {'a': 'aa', 'b': ['bb', six.b('éàù@')], 'f': f}
h = {'content-type': "multipart/form-data"}
body, headers = multipart_form_encode(b, h, uuid.uuid4().hex)
r = request(u, method='POST', body=body, headers=headers)
t.eq(r.status_int, 200)
t.eq(int(r.body_string()), l)
开发者ID:pashinin,项目名称:restkit,代码行数:11,代码来源:008-tst-request.py
示例19: postTwitter
def postTwitter(graph, openid, msg):
"""
openid is an RDF node that foaf:holdsAccount which is a mb:TwitterAccount
"""
oauthFilter = makeOauthFilter(graph, openid)
resp = restkit.request(
method="POST",
url="http://api.twitter.com/1.1/statuses/update.json",
filters=[oauthFilter],
body={'status' : msg})
if resp.status_int != 200:
raise ValueError("%s: %s" % (resp.status, resp.body_string()))
开发者ID:drewp,项目名称:magma,代码行数:12,代码来源:microblog.py
示例20: getRequest
def getRequest(self):
"""
"""
query = urllib.urlencode(self.parameters)
url = 'https://' + self.ses.host + '/?' + query
req = restkit.request(url, method=self.method, headers=self.headers)
body = req.body_string()
return {
'status': req.status_int,
'body': body
}
开发者ID:grangier,项目名称:python-aws-ses,代码行数:12,代码来源:__init__.py
注:本文中的restkit.request函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论