首页前端开发HTML分享一个自己用得云函数代码

分享一个自己用得云函数代码

时间2023-07-05 20:21:02发布访客分类HTML浏览1287
导读:云函数端不到30行代码可匹配客户端request多种类型请求#!/usr/bin/env python # -*- coding:utf-8 -*- import requests import urllib3 urllib3.disab...

云函数端不到30行代码可匹配客户端request多种类型请求

#!/usr/bin/env python
# -*- coding:utf-8 -*-
import requests
import urllib3

urllib3.disable_warnings()

def main_handler(event, context):
    try:
        args = eval(event['body'])
    except:
        return {
"isBase64Encoded": False,
        "statusCode": 200,
        "headers": {
    'Content-Type': 'text/html;
 charset=utf-8'}
,
        "body": str(("error_body", str({
    'Content-Type': 'text/html;
 charset=utf-8'}
), str(404), "", "utf-8"))}

    method, url, data, headers, cookies, files, auth, timeout, allow_redirects, hooks, stream, verify, cert, json = args
    try:
        html = requests.request(method, url, data=data, headers=headers, cookies=cookies, files=files, auth=auth, timeout=timeout, allow_redirects=allow_redirects, hooks=hooks, stream=stream, verify=verify, cert=cert, json=json)
        res = (str(html.text), str(html.headers), str(html.status_code), str(html.cookies), str(html.encoding))
        status_code = html.status_code
    except:
        status_code = 404
        res = ("timeout", str({
    'Content-Type': 'text/html;
 charset=utf-8'}
), str(status_code), "", "utf-8")
    return {

        "isBase64Encoded": False,
        "statusCode": status_code,
        "headers": {
    'Content-Type': 'text/html;
 charset=utf-8'}
,
        "body": str(res)
    }

本地可通过python 请求接口部分代码

# 使用云函数代理
    def yunProxy(self, method, url, data=None, headers=None, cookies=None, files=None, auth=None, timeout=time_out, allow_redirects=True, hooks=None, stream=None, verify=False, cert=None, json=None):
        yUrl = self.proxyList[random.randint(1, len(self.proxyList) - 1)].decode().strip()
        body = (method, url, data, headers, cookies, files, auth, timeout, allow_redirects, hooks, stream, verify, cert, json)
        try:
            html = requests.post(url=yUrl, data=str(body).encode('utf-8'), verify=False, timeout=20)
        except Exception as e:
            return None
        try:
            text, headers, status_code, cookies, htmlEncoding = eval(html.text)
        except Exception as e:
            text, headers, status_code, cookies, htmlEncoding = ("", {
}
    , 200, "", "")
        res = Html(str(text), int(status_code), text.encode(), eval(headers), cookies, htmlEncoding)
        return res

声明:本文内容由网友自发贡献,本站不承担相应法律责任。对本内容有异议或投诉,请联系2913721942#qq.com核实处理,我们将尽快回复您,谢谢合作!

html云函数codestatustext

若转载请注明出处: 分享一个自己用得云函数代码
本文地址: https://pptw.com/jishu/290722.html
Apache2与PHP5 for WinXP简单配置技巧 客服系统源码聊天界面,vue elementui中v-html渲染的内容,增加大图预览功能

游客 回复需填写必要信息