初始化项目
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
"""
|
||||
数字城管对接 API 基础功能。
|
||||
"""
|
||||
import dock
|
||||
|
||||
|
||||
ApiUrl = "http://221.224.13.41:28086/eUrbanMIS"
|
||||
"""
|
||||
对接 API 根目录。
|
||||
"""
|
||||
|
||||
GisUrl = "http://221.224.13.41:28089/eUrbanGIS"
|
||||
"""
|
||||
对接 GIS 地址。暂无实际用处。
|
||||
"""
|
||||
|
||||
|
||||
async def new_api_request(api_url: str, request_body: dict, method: str = 'POST',
|
||||
timeout: float = dock.DEFAULT_TIMEOUT, use_form: bool = True, headers: dict = None):
|
||||
"""
|
||||
构造一个 API 请求对象
|
||||
|
||||
:param api_url: API 地址,以斜杠开头的 URI 地址,非完整 URL
|
||||
:param request_body: 请求体,即所有请求参数
|
||||
:param method: 请求提交方式
|
||||
:param timeout: 超时时长
|
||||
:param use_form: 是否使用表单(Form)方式提交
|
||||
:param headers: 头数据,最高优先级
|
||||
:return: HTTPRequest 对象
|
||||
"""
|
||||
# Cookie
|
||||
from dock.dcm import dcm_security
|
||||
cookie_header = await dcm_security.get_cookies()
|
||||
|
||||
# 构建扩展头
|
||||
user_agent, browser_ver, os_name = dock.get_random_user_agent()
|
||||
extra_headers = {
|
||||
'Cookie': cookie_header,
|
||||
'User-Agent': user_agent,
|
||||
}
|
||||
if headers is not None:
|
||||
extra_headers = {**extra_headers, **headers}
|
||||
|
||||
# 构造请求对象
|
||||
request = dock.new_http_request(
|
||||
url=f"{ApiUrl}{api_url}",
|
||||
body=request_body,
|
||||
method=method,
|
||||
timeout=timeout,
|
||||
use_form=use_form,
|
||||
extra_headers=extra_headers,
|
||||
)
|
||||
return request
|
||||
Reference in New Issue
Block a user