python get函数导入_Python request.get_method方法代码示例

本文整理汇总了Python中urllib.request.get_method方法的典型用法代码示例。如果您正苦于以下问题:Python request.get_method方法的具体用法?Python request.get_method怎么用?Python request.get_method使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在模块urllib.request的用法示例。

在下文中一共展示了request.get_method方法的23个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: check_connection

​点赞 6

# 需要导入模块: from urllib import request [as 别名]

# 或者: from urllib.request import get_method [as 别名]

def check_connection(self):

request = urllib.request.Request(self._api_hostname)

request.get_method = lambda: 'GET'

try:

data = self._request('/api/v1/service-online', {}, force=True)

except URLError as e:

TestLogger.log_warning('Problem with connecting to {} ({}).'.format(self._api_hostname, e))

return

else:

self._has_connection = (

200 >= self._last_response.status < 400

) and data.get('success')

if data.get('msg'):

TestLogger.log_warning(data.get('msg'))

self.version = data.get('version')

开发者ID:thejoeejoee,项目名称:VUT-FIT-IFJ-2017-toolkit,代码行数:18,

示例2: put

​点赞 6

# 需要导入模块: from urllib import request [as 别名]

# 或者: from urllib.request import get_method [as 别名]

def put(self, location, params=None):

"""Dispatch a PUT request to a SeaMicro chassis.

The seamicro box has order-dependent HTTP parameters, so we build

our own get URL, and use a list vs. a dict for data, as the order is

implicit.

"""

opener = urllib.request.build_opener(urllib.request.HTTPHandler)

url = self.build_url(location, params)

request = urllib.request.Request(url)

request.get_method = lambda: "PUT"

request.add_header("content-type", "text/json")

response = opener.open(request)

json_data = self.parse_response(url, response)

return json_data["result"]

开发者ID:maas,项目名称:maas,代码行数:18,

示例3: OpenWebRequest

​点赞 5

# 需要导入模块: from urllib import request [as 别名]

# 或者: from urllib.request import get_method [as 别名]

def OpenWebRequest(uri, post_data, headers, timeout, get_method=None):

request = urllib.request.Request(uri, post_data, headers)

if get_method:

request.get_method = get_method

if timeout == 0:

response = urllib.request.urlopen(request)

else:

response = urllib.request.urlopen(request, timeout=timeout)

return response

开发者ID:rapid7,项目名称:nexpose-client-python,代码行数:11,

示例4: ExecuteWebRequest

​点赞 5

# 需要导入模块: from urllib import request [as 别名]

# 或者: from urllib.request import get_method [as 别名]

def ExecuteWebRequest(uri, post_data, headers, timeout, get_method=None):

response = OpenWebRequest(uri, post_data, headers, timeout, get_method)

return response.read().decode('utf-8')

开发者ID:rapid7,项目名称:nexpose-client-python,代码行数:5,

示例5: ExecuteWithPostData_JSON

​点赞 5

# 需要导入模块: from urllib import request [as 别名]

# 或者: from urllib.request import get_method [as 别名]

def ExecuteWithPostData_JSON(session_id, uri, sub_url, timeout, post_data, get_method):

headers = CreateHeadersWithSessionCookieAndCustomHeader(session_id)

headers["Content-Type"] = "application/json; charset=UTF-8"

if isinstance(post_data, dict) or isinstance(post_data, list):

post_data = json.dumps(post_data, separators=(',', ':'))

post_data = post_data.encode('utf-8')

return ExecuteWebRequest(uri + sub_url, post_data, headers, timeout, get_method)

开发者ID:rapid7,项目名称:nexpose-client-python,代码行数:9,

示例6: check_target

​点赞 5

# 需要导入模块: from urllib import request [as 别名]

# 或者: from urllib.request import get_method [as 别名]

def check_target(target, options):

'''

Just put a protocol to a valid IP and check if connection works,

returning HEAD response

'''

# Recover used options

ssldisabled = options.ssldisabled

useget = options.useget

proxy = options.proxy

response = None

target = normalize(target)

try:

request = urllib.request.Request(target, headers=client_headers)

# Set method

method = 'GET' if useget else 'HEAD'

request.get_method = lambda: method

# Set proxy

set_proxy(proxy)

# Set certificate validation

if ssldisabled:

context = get_unsafe_context()

response = urllib.request.urlopen(request, timeout=10, context=context)

else:

response = urllib.request.urlopen(request, timeout=10)

except Exception as e:

print_error(e)

sys.exit(1)

if response is not None:

return response

print("Couldn't read a response from server.")

sys.exit(3)

开发者ID:meliot,项目名称:shcheck,代码行数:39,

示例7: open_request

​点赞 5

# 需要导入模块: from urllib import request [as 别名]

# 或者: from urllib.request import get_method [as 别名]

def open_request(url, query_params=None, user_agent=None, post_data=None, referer=None, get_method=None, cookies=False,

timeout=None, headers=None, **kwargs):

if query_params is None:

query_params = {}

if user_agent is None:

user_agent = ua_cloudbot

query_params.update(kwargs)

url = prepare_url(url, query_params)

request = urllib.request.Request(url, post_data)

if get_method is not None:

request.get_method = lambda: get_method

if headers is not None:

for header_key, header_value in headers.items():

request.add_header(header_key, header_value)

request.add_header('User-Agent', user_agent)

if referer is not None:

request.add_header('Referer', referer)

if cookies:

opener = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(jar))

else:

opener = urllib.request.build_opener()

if timeout:

return opener.open(request, timeout=timeout)

return opener.open(request)

# noinspection PyShadowingBuiltins

开发者ID:TotallyNotRobots,项目名称:CloudBot,代码行数:40,

示例8: open

​点赞 5

# 需要导入模块: from urllib import request [as 别名]

# 或者: from urllib.request import get_method [as 别名]

def open(url, query_params=None, user_agent=None, post_data=None,

referer=None, get_method=None, cookies=False, timeout=None, headers=None,

**kwargs): # pylint: disable=locally-disabled, redefined-builtin # pragma: no cover

warnings.warn(

"http.open() is deprecated, use http.open_request() instead.",

DeprecationWarning

)

return open_request(

url, query_params=query_params, user_agent=user_agent, post_data=post_data, referer=referer,

get_method=get_method, cookies=cookies, timeout=timeout, headers=headers, **kwargs

)

开发者ID:TotallyNotRobots,项目名称:CloudBot,代码行数:14,

示例9: test_default_values

​点赞 5

# 需要导入模块: from urllib import request [as 别名]

# 或者: from urllib.request import get_method [as 别名]

def test_default_values(self):

Request = urllib.request.Request

request = Request("http://www.python.org")

self.assertEqual(request.get_method(), 'GET')

request = Request("http://www.python.org", {})

self.assertEqual(request.get_method(), 'POST')

开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:8,

示例10: test_with_method_arg

​点赞 5

# 需要导入模块: from urllib import request [as 别名]

# 或者: from urllib.request import get_method [as 别名]

def test_with_method_arg(self):

Request = urllib.request.Request

request = Request("http://www.python.org", method='HEAD')

self.assertEqual(request.method, 'HEAD')

self.assertEqual(request.get_method(), 'HEAD')

request = Request("http://www.python.org", {}, method='HEAD')

self.assertEqual(request.method, 'HEAD')

self.assertEqual(request.get_method(), 'HEAD')

request = Request("http://www.python.org", method='GET')

self.assertEqual(request.get_method(), 'GET')

request.method = 'HEAD'

self.assertEqual(request.get_method(), 'HEAD')

开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:14,

示例11: get_method

​点赞 5

# 需要导入模块: from urllib import request [as 别名]

# 或者: from urllib.request import get_method [as 别名]

def get_method(self):

"""Return a string indicating the HTTP request method."""

default_method = "POST" if self.data is not None else "GET"

return getattr(self, 'method', default_method)

开发者ID:CedricGuillemet,项目名称:Imogen,代码行数:6,

示例12: redirect_request

​点赞 5

# 需要导入模块: from urllib import request [as 别名]

# 或者: from urllib.request import get_method [as 别名]

def redirect_request(self, req, fp, code, msg, headers, newurl):

"""Return a Request or None in response to a redirect.

This is called by the http_error_30x methods when a

redirection response is received. If a redirection should

take place, return a new Request to allow http_error_30x to

perform the redirect. Otherwise, raise HTTPError if no-one

else should try to handle this url. Return None if you can't

but another Handler might.

"""

m = req.get_method()

if (not (code in (301, 302, 303, 307) and m in ("GET", "HEAD")

or code in (301, 302, 303) and m == "POST")):

raise HTTPError(req.full_url, code, msg, headers, fp)

# Strictly (according to RFC 2616), 301 or 302 in response to

# a POST MUST NOT cause a redirection without confirmation

# from the user (of urllib.request, in this case). In practice,

# essentially all clients do redirect in this case, so we do

# the same.

# Be conciliant with URIs containing a space. This is mainly

# redundant with the more complete encoding done in http_error_302(),

# but it is kept for compatibility with other callers.

newurl = newurl.replace(' ', '%20')

CONTENT_HEADERS = ("content-length", "content-type")

newheaders = {k: v for k, v in req.headers.items()

if k.lower() not in CONTENT_HEADERS}

return Request(newurl,

headers=newheaders,

origin_req_host=req.origin_req_host,

unverifiable=True)

# Implementation note: To avoid the server sending us into an

# infinite loop, the request object needs to track what URLs we

# have already seen. Do this by adding a handler-specific

# attribute to the Request object.

开发者ID:CedricGuillemet,项目名称:Imogen,代码行数:40,

示例13: _get_content_length

​点赞 5

# 需要导入模块: from urllib import request [as 别名]

# 或者: from urllib.request import get_method [as 别名]

def _get_content_length(self, request):

return http.client.HTTPConnection._get_content_length(

request.data,

request.get_method())

开发者ID:CedricGuillemet,项目名称:Imogen,代码行数:6,

示例14: _http_response

​点赞 5

# 需要导入模块: from urllib import request [as 别名]

# 或者: from urllib.request import get_method [as 别名]

def _http_response(self, request, response):

fetch = {

'url': request.full_url,

'method': request.get_method(),

'response_code': response.code,

'response_headers': response.headers,

}

self.fetches.append(fetch)

return response

开发者ID:internetarchive,项目名称:brozzler,代码行数:11,

示例15: check_url

​点赞 5

# 需要导入模块: from urllib import request [as 别名]

# 或者: from urllib.request import get_method [as 别名]

def check_url(url,ua):

global total_requests

total_requests += 1

request = urllib.request.Request(url)

request.add_header('User-Agent', ua)

request.get_method = lambda: 'HEAD'

try:

urllib.request.urlopen(request)

return '1'

except urllib.request.HTTPError:

return '0'

开发者ID:Tuhinshubhra,项目名称:CMSeeK,代码行数:13,

示例16: url_is_alive

​点赞 5

# 需要导入模块: from urllib import request [as 别名]

# 或者: from urllib.request import get_method [as 别名]

def url_is_alive(url):

request = urllib.request.Request(url)

request.get_method = lambda: 'HEAD'

try:

urllib.request.urlopen(request)

return True

except urllib.request.HTTPError:

return False

开发者ID:yalesong,项目名称:pvse,代码行数:10,

示例17: put_request

​点赞 5

# 需要导入模块: from urllib import request [as 别名]

# 或者: from urllib.request import get_method [as 别名]

def put_request(self, api_path):

request = urllib.request.Request(self.arachni_url + api_path)

request.get_method = lambda: 'PUT'

return urllib.request.urlopen(request).read().decode('utf8')

开发者ID:jjf012,项目名称:PassiveScanner,代码行数:6,

示例18: delete_request

​点赞 5

# 需要导入模块: from urllib import request [as 别名]

# 或者: from urllib.request import get_method [as 别名]

def delete_request(self, api_path):

request = urllib.request.Request(self.arachni_url + api_path)

request.get_method = lambda: 'DELETE'

return urllib.request.urlopen(request).read().decode('utf8')

开发者ID:jjf012,项目名称:PassiveScanner,代码行数:6,

示例19: http_request

​点赞 5

# 需要导入模块: from urllib import request [as 别名]

# 或者: from urllib.request import get_method [as 别名]

def http_request(self, request):

host, full_url = request.host, request.get_full_url()

url_path = full_url[full_url.find(host) + len(host):]

log_url ( self.log, "Requesting: ", request.get_full_url(), TRACE_LEVEL )

self.log.log(self.log_level, "%s %s" % (request.get_method(), url_path))

for header in request.header_items():

self.log.log(self.log_level, " . %s: %s" % header[:])

return request

开发者ID:clstoulouse,项目名称:motu-client-python,代码行数:12,

示例20: api

​点赞 5

# 需要导入模块: from urllib import request [as 别名]

# 或者: from urllib.request import get_method [as 别名]

def api(endpoint, method="GET", data=None, params=[]):

base_url = BASE_URL or "http://127.0.0.1:4040/"

if params:

endpoint += "?%s" % urlencode([(x, params[x]) for x in params])

request = urllib.request.Request("%sapi/%s" % (base_url, endpoint))

if method != "GET":

request.get_method = lambda: method

request.add_header("Content-Type", "application/json")

response = urllib.request.urlopen(request, json.dumps(data) if data else None)

try:

return json.loads(response.read())

except:

return None

开发者ID:peakwinter,项目名称:python-ngrok,代码行数:15,

示例21: api

​点赞 5

# 需要导入模块: from urllib import request [as 别名]

# 或者: from urllib.request import get_method [as 别名]

def api(endpoint, method="GET", data=None):

if not PUBLIC_ID or not SECRET_TOKEN:

raise Exception("Public ID and secret token must be declared")

authstr = base64.encodestring('%s:%s' % (PUBLIC_ID, SECRET_TOKEN)).replace('\n', '')

request = urllib.request.Request("https://api.ngrok.com/%s" % endpoint)

if method != "GET":

request.get_method = lambda: method

request.add_header("Authorization", "Basic %s" % authstr)

request.add_header("Content-Type", "application/json")

response = urllib.request.urlopen(request, json.dumps(data) if data else None)

try:

return json.loads(response.read())

except:

return None

开发者ID:peakwinter,项目名称:python-ngrok,代码行数:16,

示例22: open

​点赞 5

# 需要导入模块: from urllib import request [as 别名]

# 或者: from urllib.request import get_method [as 别名]

def open(url, query_params=None, user_agent=None, post_data=None,

referer=None, get_method=None, cookies=False, timeout=None, headers=None, **kwargs):

if query_params is None:

query_params = {}

if user_agent is None:

user_agent = ua_cloudbot

query_params.update(kwargs)

url = prepare_url(url, query_params)

request = urllib.request.Request(url, post_data)

if get_method is not None:

request.get_method = lambda: get_method

if headers is not None:

for header_key, header_value in headers.items():

request.add_header(header_key, header_value)

request.add_header('User-Agent', user_agent)

if referer is not None:

request.add_header('Referer', referer)

if cookies:

opener = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(jar))

else:

opener = urllib.request.build_opener()

if timeout:

return opener.open(request, timeout=timeout)

else:

return opener.open(request)

开发者ID:CloudBotIRC,项目名称:CloudBot,代码行数:37,

示例23: get_authorization

​点赞 4

# 需要导入模块: from urllib import request [as 别名]

# 或者: from urllib.request import get_method [as 别名]

def get_authorization(self, req, chal):

try:

realm = chal['realm']

nonce = chal['nonce']

qop = chal.get('qop')

algorithm = chal.get('algorithm', 'MD5')

# mod_digest doesn't send an opaque, even though it isn't

# supposed to be optional

opaque = chal.get('opaque', None)

except KeyError:

return None

H, KD = self.get_algorithm_impls(algorithm)

if H is None:

return None

user, pw = self.passwd.find_user_password(realm, req.full_url)

if user is None:

return None

# XXX not implemented yet

if req.data is not None:

entdig = self.get_entity_digest(req.data, chal)

else:

entdig = None

A1 = "%s:%s:%s" % (user, realm, pw)

A2 = "%s:%s" % (req.get_method(),

# XXX selector: what about proxies and full urls

req.selector)

if qop == 'auth':

if nonce == self.last_nonce:

self.nonce_count += 1

else:

self.nonce_count = 1

self.last_nonce = nonce

ncvalue = '%08x' % self.nonce_count

cnonce = self.get_cnonce(nonce)

noncebit = "%s:%s:%s:%s:%s" % (nonce, ncvalue, cnonce, qop, H(A2))

respdig = KD(H(A1), noncebit)

elif qop is None:

respdig = KD(H(A1), "%s:%s" % (nonce, H(A2)))

else:

# XXX handle auth-int.

raise URLError("qop '%s' is not supported." % qop)

# XXX should the partial digests be encoded too?

base = 'username="%s", realm="%s", nonce="%s", uri="%s", ' \

'response="%s"' % (user, realm, nonce, req.selector,

respdig)

if opaque:

base += ', opaque="%s"' % opaque

if entdig:

base += ', digest="%s"' % entdig

base += ', algorithm="%s"' % algorithm

if qop:

base += ', qop=auth, nc=%s, cnonce="%s"' % (ncvalue, cnonce)

return base

开发者ID:CedricGuillemet,项目名称:Imogen,代码行数:61,

注:本文中的urllib.request.get_method方法示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。

优化一下下面的代码def FileUploads_modelform(request): """ 批量上传文件 方法三:采用modelform上传,超级简单,只需要实例化表单的时候 接收一下表单里边字符串数据和文件,然后利用表单的save()方法保存一下数据即可 :param request: :return: """ # 判断提交方式GET 或POST if request.method == 'POST': File_ModelForm = FileUpload_ModelForm(request.POST, request.FILES) # 实例化FileUploadForm表单,注意获取数据的方式 if File_ModelForm.is_valid(): # file = File_ModelForm.cleaned_data['file'] # 对于文件,自动保存 # 字段+上传路径自动保存到数据库 # file_form = File_ModelForm.save() # 保存表单到数据库 # 多属性保存 Upload_File = File_ModelForm.save(commit=False) # Upload_File.file_url = Upload_File.file_url.temporary_file_path() # 文件路径 # 调用get_optimized_file_type函数获取优化文件类型 # optimized_file_type = get_optimized_file_type(Upload_File.file_url) Upload_File.file_name = Upload_File.file_url.name # 文件名 Upload_File.file_size = Upload_File.file_url.size # 文件大小 Upload_File.file_update_author = request.user.realname # 获取文件类型 # Get the file content type uploaded_file_type, encoding = mimetypes.guess_type(Upload_File.file_url.path) Upload_File.file_type = uploaded_file_type # Upload_File.file_type = Upload_File.file_url.content_type # optimized_file_type = get_optimized_file_type(file_url) Upload_File.save() # 其他操作,例如返回成功页面或其他处理 # return render(request, 'zadmin/pages/File_Uploads.html', {'file_form': file_form}) return HttpResponse("文件上传成功!") else: file_form = FileUpload_ModelForm() return render(request, 'zadmin/pages/File_Uploads.html', {'file_form': file_form})
07-15
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值