コード例 #1
0
ファイル: daily_backup.py プロジェクト: JokerQyou/toolset
def push_notification(s):
    '''
    Push a notification via Telegram bot
    '''
    http_post(
        'https://eth.api.mynook.info/push',
        data={
            'code': PUSH_CODE,
            'text': s,
        }
    )
コード例 #2
0
def query_stations(station_id=None):
    # Set the query url. This only needs to be changed if the API changes.
    url = "https://api.digitransit.fi/routing/v1/routers/hsl/index/graphql"
    # Check if one station or all stations should be queried.
    if station_id:
        # Master keyword used in retrieving the data.
        keyword = "bikeRentalStation"
        # Values to be retrieved.
        values = "stationId name state bikesAvailable spacesAvailable allowDropoff"
        # String used in the query. The API requires curly spaces in the query string, thus making .format() syntax very, very ugly.
        query = "{{{keyword}(id: \"{station}\") {{{values}}}}}".format(
            keyword=keyword, station=station_id, values=values)
    else:
        # Master keyword used in retrieving the data.
        keyword = "bikeRentalStations"
        # Values to be retrieved.
        values = "stationId name"
        # String used in the query. The API requires curly spaces in the query string, thus making .format() syntax very, very ugly.
        query = "{{{keyword} {{{values}}}}}".format(keyword=keyword,
                                                    values=values)
    # Query the API.
    reply = http_post(url, json={"query": query})
    # Get the JSON-formatted version of the reply and extract the station information.
    reply_json = reply.json()
    reply_data = reply_json["data"][keyword]
    # All done, return.
    return reply_data
コード例 #3
0
def get_zhengxin_AcvitaveCode(request):
    """
        获取短信验证码
    """
    phone_number = request.POST["number"]

    data = {"method": "getAcvitaveCode",
            "mobileTel": phone_number}

    headers = DEFAULT_REQUEST_HEADERS.copy()
    headers["Referer"] = "https://ipcrs.pbccrc.org.cn/userReg.do"
    kwargs = {"timeout": 6,
              "verify": False,
              "headers": headers,
              "cookies": request.session.get("req_cookie")
              }

    resp = http_post("https://ipcrs.pbccrc.org.cn/userReg.do", data, **kwargs)
    text = resp.text

    # TODO 容错
    ret_data = {}
    if resp.status_code == 200 and text:
        add_ajax_ok_json(ret_data)
        ret_data["tcId"] = text
    else:
        add_ajax_error_json(ret_data)

    return JsonResponse(ret_data)
コード例 #4
0
def access_token(request):
    result = {"code": 0}
    try:
        # 接收密文
        body = data_loads(request.body)
        if not isinstance(body, dict):
            raise ValueError("arguments must json")
        elif body["cipher_text"] is None or body["cipher_text"] == "":
            raise ValueError("arguments cipher_text is not null")
        # 解密
        plain_text = rsa_long_decrypt(settings.PRIVATE_KEY,
                                      body["cipher_text"])
        plain_text = data_loads(plain_text)
        if not isinstance(plain_text, dict):
            raise ValueError("plain_text must json")
        # 请求access token
        token_url = "%so/token/?client_id=%s&grant_type=client_credentials&client_secret=%s" % \
                    (WEB_SETTINGS_ACCESS_DOMAIN, plain_text["client_id"], plain_text["client_secret"])
        res = http_post(token_url)
        result["code"] = 1
        result["body"] = data_loads(res.text)
        result["message"] = "success"
    except Exception as e:
        result["message"] = "error.detail:%s" % str(e)

    return JsonResponse(result)
コード例 #5
0
ファイル: client.py プロジェクト: OPWEN/opwen-webapp
    def upload(self, resource_id, container):
        payload = {
            'resource_id': resource_id,
        }

        response = http_post(self._upload_url, json=payload)
        response.raise_for_status()
コード例 #6
0
def _get_mobile_login_sms_captcha(args):
    """移动发送登录短信验证码"""
    ret_data = {}
    username = args["username"].strip()
    url = "https://login.10086.cn/sendRandomCodeAction.action"

    form_data = {
        "userName": username,
        "type": "01",
        "channelID": "12003"
    }

    key = username + ACCOUNT_CRAWLING_SMS_HEADERS_SSDB_SUFFIX + args["account_type"]
    try:
        ssdb_conn = get_ssdb_conn()
        headers = ssdb_conn.get(key)
        if headers is not None:
            sms_content = http_post(url, headers=eval(headers), data=form_data, verify=False).text
            if sms_content == '0':
                add_ajax_ok_json(ret_data)
            elif sms_content == '2':
                add_ajax_error_json(ret_data, "当日短信验证码已达上限,请明天再试!")
            else:
                add_ajax_error_json(ret_data, "短信验证码发送失败,请重试!")
        else:
            add_ajax_error_json(ret_data, "无法获取短信验证码,请刷新页面重试!")
    except Exception:
        add_ajax_error_json(ret_data, "无法获取短信验证码,请重试。")

    return JsonResponse(ret_data)
コード例 #7
0
def submit_question(request):
    """
        用户提交答案:
    :param request:
    :return:
    """
    args = request.POST
    session = request.session
    # awsers = args.get('st')
    datas = session.get('quest_data')
    cookies = session.get('question_cookies')
    for x in range(5):
        i = str(x)
        datas['kbaList[' + i + '].answerresult'] = args.get("st[key[" + i + "].options]")
        datas['kbaList[' + i + '].options'] = args.get("st[key[" + i + "].options]")

    url = 'https://ipcrs.pbccrc.org.cn/reportAction.do?method=submitKBA'
    headers = HEADERS.copy()
    headers['Referer'] = 'https://ipcrs.pbccrc.org.cn/reportAction.do?method=checkishasreport'
    response = http_post(url=url, data=datas, headers=headers, cookies=cookies, verify=False)
    result = dict()
    try:
        msg = etree.HTML(response.text).xpath('//div[@class="span-grey2 span-14 p1 margin_top_80"]')[0]
        if '您的查询申请已提交' in msg.xpath('string(.)'):
            result['msg'] = msg.xpath('string(.)')
            add_ajax_ok_json(result)
        else:
            add_ajax_error_json(result)
    except Exception:
        add_ajax_error_json(result)
        result['msg'] = "用户提交异常,请<a href='/account_spider/zhengxin/'>返回</a>重新提交;"

    return JsonResponse(result)
コード例 #8
0
    def upload(self, resource_id, container):
        payload = {
            'resource_id': resource_id,
        }

        response = http_post(self._upload_url, json=payload)
        response.raise_for_status()
コード例 #9
0
def back_submit_passwd_question(request):
    args = request.POST
    session = request.session
    # awsers = args.get('dict')
    datas = session.get('submit_passwd_quest_data')
    passwd_cookies = session.get('passwd_cookies')
    for x in range(5):
        i = str(x)
        datas['kbaList[' + i + '].answerresult'] = args.get("dict[key[" + i + "].options]")
        datas['kbaList[' + i + '].options'] = args.get("dict[key[" + i + "].options]")

    url = 'https://ipcrs.pbccrc.org.cn/resetPassword.do'
    headers = HEADERS.copy()
    headers['Referer'] = url
    response = http_post(url=url, data=datas, headers=headers, cookies=passwd_cookies, verify=False)
    test = ''
    try:
        test = etree.HTML(response.text).xpath('//font[@class="span-14 padding_left_130"]/text()')[0]
    except Exception:
        pass

    result = {}
    if '您的重置密码申请已提交' in test:
        result['msg'] = test
        add_ajax_ok_json(result)
    else:
        add_ajax_error_json(result, "重置密码失败")

    return JsonResponse(result)
コード例 #10
0
def update_password(request):
    """
    找回密码第三步:更新密码
    :param request:
    :return:
    """
    ret_data = {}
    succ = False
    try:
        args = request.POST
        new_password = args.get("new_password")
        key = args.get("ret_key")
        mobile = args.get("mobile")
        need_history_name = args.get("history_name", "")

        # rsa_tool = RsaUtil(key_is_hex=True)
        # en_pwd = rsa_tool.encrypt(new_password, pubkey=rsa_pubkey, get_hex=True)

        rsa_tool = RsaNoPadding(pubkey=rsa_pubkey)
        en_pwd = rsa_tool.encrypt(new_password)

        params = {
            "host": host,
            "key": key,
            "en_newpwd": quote(en_pwd),
            "mobile": mobile,
            "name": quote(need_history_name),
            "eid": eid,
            "fp": fp,
        }
        my_headers = HEADERS.copy()
        referer = "https://safe.jd.com/findPwd/resetPassword.action?key={key}".format(key=key)
        my_headers["Referer"] = referer
        post_url = "{host}/findPwd/doResetPwd.action?key={key}&password={en_newpwd}&" \
                   "mobile={mobile}&historyName={name}&eid={eid}&fp={fp}".format(**params)
        ret_json = http_post(post_url, headers=my_headers, verify=False).json()
        result_code = ret_json.get("resultCode")
        if result_code == "0":
            msg = "重置密码成功"
            succ = True
        elif result_code in ["101", "102", "112", "116", "606",
                             "801", "802", "803", "804"]:
            msg = ret_json.get("resultMessage", "")
        elif result_code == "passwordError":
            msg = "密码设置级别太低"
        elif result_code in ("timeOut", "202"):
            msg = "操作超时"
        elif result_code == "mobileNameError":
            msg = "历史收货人姓名不能为手机号"
        else:
            msg = ret_json.get("resultMessage", "找回密码失败,未知错误")
        if succ:
            add_ajax_ok_json(ret_data)
        else:
            add_ajax_error_json(ret_data, msg)
    except Exception:
        add_ajax_error_json(ret_data, "找回密码第三步:更新密码失败")

    return JsonResponse(ret_data)
コード例 #11
0
    def __call__(self, client_id: str, domain: str) -> None:
        if not self._key:
            self.log_warning('No key, skipping mailbox setup for %s', domain)
            return

        http_post(url=MAILBOX_URL,
                  json={
                      'hostname': domain,
                      'url': INBOX_URL.format(client_id),
                      'spam_check': True,
                      'send_raw': True,
                  },
                  headers={
                      'Authorization': 'Bearer {}'.format(self._key),
                  }).raise_for_status()

        self.log_debug('Set up mailbox for %s', domain)
コード例 #12
0
def http_request(url, method="GET", is_img=False, get_cookies=False, cookies=None,
                 headers=None, timeout=10, referer=None, data=None, charset=None):
    """
    处理HTTP请求
    :param url:
    :param method:
    :param is_img:
    :param get_cookies:
    :param cookies:
    :param headers:
    :param timeout:
    :param referer:
    :param data:
    :param charset:
    :return:
    """
    if not url and isinstance(url, str):
        raise TypeError
    if referer is None:
        referer = "https://ipcrs.pbccrc.org.cn/"
    if headers is None:
        headers = {
            "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
            "Accept-Encoding": "gzip, deflate, br",
            "Accept-Language": "zh-CN,zh;q=0.8",
            "Host": "ipcrs.pbccrc.org.cn",
            "Upgrade-Insecure-Requests": "1",
            "User-Agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) "
                          "Chrome/60.0.3112.113 Safari/537.36",
            "Referer": referer,
        }
    if method == "GET":
        response = http_get(url, cookies=cookies, timeout=timeout, headers=headers, verify=False)
    else:
        response = http_post(url, cookies=cookies, timeout=timeout, headers=headers, data=data, verify=False)
    if response.status_code == 200:
        if is_img:
            content = response.content
        else:
            content = response.content
            if response.text.find("charset=gbk") >= 0:
                content = content.decode("gbk")
            elif response.text.find("charset=utf-8") >= 0:
                content = content.decode("utf-8")
            else:
                if charset is not None:
                    content = content.decode(charset)
                else:
                    content = response.text
        print("下载网页成功: %s" % url)
        if get_cookies:
            cookies = response.cookies
            return [content, cookies]
        return content
    else:
        print("请求失败:%d" % response.status_code)
        return None
コード例 #13
0
def xuexin_find_password_step2(request):
    """
    学信网找回密码第二步
    https://account.chsi.com.cn/account/forgot/rtvbymphone.action post
    captch	88
    mphone	15908143404
    ctoken	9671bdc3552f4ebf96b21ef5fa9ffab0
    xm	胡明星1
    sfzh	510722198609271058

    重置密码短信已发送至15908143404,登录用户名15908143404
    :param request:
    :return:
    """
    args = request.POST
    captch = args.get("captch", "")
    mphone = args.get("mphone", "")
    xm = args.get("xm", "")
    sfzh = args.get("sfzh", "")
    ctoken = args.get("ctoken", "")

    req_cookie = request.session.get("req_cookie")
    url = "https://account.chsi.com.cn/account/forgot/rtvbymphone.action"
    data = {
        "captch": captch,
        "mphone": mphone,
        "ctoken": ctoken,
        "xm": xm,
        "sfzh": sfzh
    }

    response = http_post(url,
                         data=data,
                         headers=HEADERS,
                         verify=False,
                         cookies=req_cookie)
    text = response.text

    result = dict()
    if "重置密码短信已发送至" in text:
        result["msg"] = "成功"
        add_ajax_ok_json(result)

        key = key_pattern.search(text)
        if key:
            key = key.group(1)
        result["key"] = key

        clst = clst_pattern.search(text)
        if clst:
            clst = clst.group(1)
        result["clst"] = clst
    else:
        err_msg = error_info_pattern.search(text)
        add_ajax_error_json(result, err_msg.group(1) if err_msg else "未知错误")

    return JsonResponse(result)
コード例 #14
0
    def upload(self, resource_id, container):
        payload = {
            'resource_id': resource_id,
            'container_name': container,
            'resource_type': self._supported_resource_type,
        }

        response = http_post(self._upload_url, json=payload)
        response.raise_for_status()
コード例 #15
0
def http_request(url,
                 method=None,
                 headers=None,
                 cookies=None,
                 data=None,
                 timeout=None,
                 logger=None):
    """
    封装网络请求
    :param url:
    :param method:
    :param headers:
    :param cookies:
    :param data:
    :param timeout:
    :param logger:
    :return: response or None
    """
    if logger is None:
        logger = default_logger
    try:
        if not isinstance(url, str):
            logger.error("URL格式不正确")
            return
        if not method:
            method = HttpData.HTTP_METHOD_GET
        if not headers:
            headers = HttpData.HTTP_DEFAULT_HEADERS
        if method == HttpData.HTTP_METHOD_GET:
            response = http_get(url,
                                headers=headers,
                                cookies=cookies,
                                timeout=timeout,
                                verify=False)
        elif method == HttpData.HTTP_METHOD_POST:
            if not data:
                data = {}
            response = http_post(url,
                                 headers=headers,
                                 cookies=cookies,
                                 data=data,
                                 timeout=timeout,
                                 verify=False)
        else:
            logger.debug("暂不支持该请求类型 ---> %s" % url)
            return
        if 200 <= response.status_code < 400:
            logger.debug("请求成功: ---> %s" % url)
            return response
        else:
            logger.error("请求失败 code:%s , ---> %s" %
                         (response.status_code, url))
            return
    except Exception as e:
        logger.exception("请求失败: %s ---> %s" % (url, str(e)))
        return
コード例 #16
0
def _send_taobao_alicloudapi(url, b64_pic):
    data = {'img': b64_pic,
            'prob': 'false'
            }
    headers = {'Authorization': 'APPCODE ' + choice(ALICLOUDAPI_APPCODE_LIST),
               }

    response = http_post(url, data=json_dumps(data), headers=headers)
    data = json_loads(response.text)
    return [i["word"] for i in data["prism_wordsInfo"]] if "prism_wordsInfo" in data else None
コード例 #17
0
def post_web_html_by_requests(url, data, proxies):
    start = time()
    resp = http_post(url,
                     data=data,
                     headers=REQ_HEADER,
                     proxies=proxies,
                     timeout=ASK_TIMEOUT)
    response_time = time() - start
    resp.close()
    return response_time if 200 == resp.status_code else None
コード例 #18
0
def xuexin_find_password_step1(request):
    """
    学信网找回密码第一步
    :param request:
    :return:
    """
    args = request.POST
    captch = args.get("captch", "")
    mphone = args.get("mphone", "")
    url = "https://account.chsi.com.cn/account/password!retrive.action"
    data = {"loginName": mphone, "captch": captch}
    req_cookie = request.session.get("req_cookie")
    response = http_post(url,
                         data=data,
                         headers=HEADERS,
                         verify=False,
                         cookies=req_cookie)
    text = response.text
    error_msg = user_retrivePsd_error_pattern.search(text)
    result = {}
    if error_msg:
        add_ajax_error_json(result, error_msg.group(1))
    else:
        result["msg"] = "成功"
        add_ajax_ok_json(result)

        # 进入找回密码的第二步
        # 获取ctoken
        ctoken = ctoken_pattern.search(text)
        if ctoken:
            ctoken = ctoken.group(1)

        data = {"ctoken": ctoken}
        url = "https://account.chsi.com.cn/account/forgot/rtvbymphoneindex.action"
        response = http_post(url,
                             data=data,
                             headers=HEADERS,
                             verify=False,
                             cookies=req_cookie)
        result["ctoken"] = ctoken_pattern.search(response.text).group(1)

    return JsonResponse(result)
コード例 #19
0
ファイル: notify.py プロジェクト: tobiashochguertel/tunman
    def notify(fw: Forwarding, msg: str):
        if not fw.validate.notify_url:
            return

        try:
            response = http_post(url=fw.validate.notify_url,
                                 data=json_dumps({'text': msg}))

            assert response.status_code == 200
        except Exception as e:
            Logger.warning('Webhook error, cannot post to "%s". Details: %s' %
                           (fw.validate.notify_url, str(e)))
コード例 #20
0
    def __call__(self, domain: str) -> None:
        if not self._key:
            self.log_warning('No key, skipping MX setup for %s', domain)
            return

        client_name = domain.split('.')[0]

        http_post(url=DNS_URL.format(self._zone),
                  json={
                      'type': 'MX',
                      'content': MX_RECORD,
                      'proxied': False,
                      'priority': 1,
                      'name': client_name,
                  },
                  headers={
                      'X-Auth-Key': self._key,
                      'X-Auth-Email': self._user,
                  }).raise_for_status()

        self.log_debug('Set up mx records for %s', domain)
コード例 #21
0
def zhengxin_reg_request(request):
    """
        执行注册第一步
    """
    args = request.POST
    data = {"method": "checkIdentity",
            "1": "on",
            "org.apache.struts.taglib.html.TOKEN": args["org.apache.struts.taglib.html.TOKEN"],
            "userInfoVO.name": args["name"],
            "userInfoVO.certType": args["certType"],
            "userInfoVO.certNo": args["certNo"],
            "_@IMGRC@_": args["Yzm"],
            }
    params = urlencode(data, encoding="gb2312")

    headers = DEFAULT_REQUEST_HEADERS.copy()
    headers['User-Agent'] = USER_AGENT
    headers["Referer"] = "https://ipcrs.pbccrc.org.cn/userReg.do"
    kwargs = {"timeout": 6,
              "verify": False,
              "headers": headers,
              "cookies": request.session.get("req_cookie"),
              "params": params,
              }

    resp = http_post("https://ipcrs.pbccrc.org.cn/userReg.do", **kwargs)

    # TODO 容错
    if resp.status_code == 200:
        text = resp.text
        token = zhengxin_token_pattern.search(text).group(1)
        error_msg = pattern_error_user.search(text)
        if error_msg:
            error_msg = error_msg.group(1).strip()
            if '验证码输入错误' in error_msg or '目前系统尚未收录您的个人信息' in error_msg:
                msg = error_msg
            elif '您已使用其他登录名注册系统并通过验证' in error_msg:
                msg = '您已使用其他登录名注册系统并通过验证,' \
                      '请点击,<a href="/account_spider/zhengxin/back_username/">找回登录名</a>'
            else:
                msg = ""

            captcha_body = _get_captcha_body(request)
            return render(request, 'public/zhengxin/show_zhengxin_crawl_register_from.html',
                          {'img_src': bytes.decode(b64encode(captcha_body)),
                           'token': token,
                           'msg': msg
                           })

        return render(request, 'public/zhengxin/show_zhengxin_crawl_register2_form.html', {'token': token})
    else:
        return HttpResponse("ERROR")
コード例 #22
0
def _get_telecom_bills_sms_captcha(args):
    """电信发送一般短信验证码"""
    ret_data = {}
    username = args["username"].strip()
    dx_conver = DXConvertData()

    url = "http://cservice.client.189.cn:8004/map/clientXML?encrypted=true"
    key = username + ACCOUNT_CRAWLING_SMS_HEADERS_SSDB_SUFFIX + args["account_type"]
    try:
        ssdb_conn = get_ssdb_conn()
        headers = ssdb_conn.get(key)
        if headers is not None:
            token = json_loads(headers)["token"]
            form_data = {
                "Request": {
                    "HeaderInfos": {
                        "ClientType": "#6.2.1#channel8#Huawei DUK-AL20#",
                        "Source": "110003",
                        "SourcePassword": "******",
                        "Token": token,
                        "UserLoginName": username,
                        "Code": "getRandomV2",
                        "Timestamp": strftime("%Y%m%d%H%M%S"),
                    },
                    "Content": {
                        "Attach": "test",
                        "FieldData": {
                            "PhoneNbr": username,
                            "SceneType": "7",
                            "Imsi": {}
                        }
                    }
                }
            }
            form_str = dx_conver.convert_request_data(form_data)
            sms_text = http_post(url, headers=CSERVICE_HEADERS, data=form_str, verify=False).text

            sms_dict = dx_conver.convert_response_data(sms_text)
            sms_str = json_dumps(sms_dict, ensure_ascii=False)
            if '"ResultCode":{"value":"0000"}' in sms_str:
                add_ajax_ok_json(ret_data)
            elif "服务中断" in sms_text:
                add_ajax_error_json(ret_data, "电信服务中断,请稍后再试!")
            else:
                add_ajax_error_json(ret_data, "发送失败:" + sms_str)
        else:
            add_ajax_error_json(ret_data, "无法获取短信验证码,请刷新页面重试!")
    except Exception:
        add_ajax_error_json(ret_data, "无法获取短信验证码,请重试。")

    return JsonResponse(ret_data)
コード例 #23
0
    def _query_github(self, access_token: str) -> Iterator[str]:
        cursor = None

        while True:
            response = http_post(
                url=github.GRAPHQL_URL,
                json={
                    'query': '''
                        query($organization:String!, $cursor:String, $first:Int!) {
                            viewer {
                                login
                                organization(login:$organization) {
                                    teams(after:$cursor, first:$first, orderBy:{ field:NAME, direction:DESC }) {
                                        edges {
                                            cursor
                                        }
                                        nodes {
                                            slug
                                        }
                                    }
                                }
                            }
                        }
                    ''',
                    'variables': {
                        'organization': self._organization,
                        'cursor': cursor,
                        'first': self._page_size,
                    },
                },
                headers={
                    'Authorization': f'Bearer {access_token}',
                },
            )
            response.raise_for_status()

            viewer = response.json()['data']['viewer']
            teams = viewer['organization']['teams']
            nodes = teams['nodes']
            edges = teams['edges']

            yield viewer['login']

            for team in nodes:
                yield team['slug']

            if len(nodes) < self._page_size:
                break

            cursor = edges[-1]['cursor']
コード例 #24
0
def jisu_alicloudapi(pic):
    """识别率90%"""
    host = 'http://tongyongwe.market.alicloudapi.com'
    path = '/generalrecognition/recognize'
    appcode = 'd6147d2ef06e4ce09ce029cae877daca'
    querys = 'type=cnen'
    url = host + path + '?' + querys

    bodys = {'pic': pic}
    headers = {'Authorization': 'APPCODE ' + appcode,
               'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
               }

    response = http_post(url, data=bodys, headers=headers)
    return response.text
コード例 #25
0
def recognize_captcha_manual(captcha_body, params=None):
    try:
        if isinstance(captcha_body, bytes):
            captcha_file_like = BytesIO(captcha_body)
        elif isinstance(captcha_body, IOBase):
            captcha_file_like = captcha_body
        else:
            raise BadCaptchaFormat

        files = {'file': captcha_file_like}
        response = http_post(RECOGNIZE_CAPTCHA_API, data=params, files=files)
        captcha_info = response.json()
        return captcha_info["captcha"] if captcha_info["status"] == 'ok' else ""
    except Exception:
        print_exc()
        return ""
コード例 #26
0
    def test_post(self):
        self.start()

        doit = {'doit': 'read a Flask tutorial', 'stuff': 'some stuff'}

        response = http_post('http://localhost:5000/dothis',
                             data=json.dumps(doit),
                             headers={
                                 'Content-Type': 'application/json',
                                 'Accept': 'application/json'
                             })

        if (response.ok):
            data = json.loads(response.content.decode('utf-8'))
            print(data)
        else:
            response.raise_for_status()
コード例 #27
0
def xuexin_find_username(request):
    """
    学信网找回用户名
    https://account.chsi.com.cn/account/password!rtvlgname.action post
    captch	88
    xm	胡明星1
    sfzh	510722198609271058

    :param request:
    :return:
    """
    args = request.POST
    captch = args.get("captch", "")
    xm = args.get("xm", "")
    sfzh = args.get("sfzh", "")

    req_cookie = request.session.get("req_cookie")
    url = "https://account.chsi.com.cn/account/password!rtvlgname.action"
    data = {"captch": captch, "xm": xm, "sfzh": sfzh}

    response = http_post(url,
                         data=data,
                         headers=HEADERS,
                         verify=False,
                         cookies=req_cookie)
    text = response.text

    result = dict()
    if "找回用户名操作完成" in text:
        add_ajax_ok_json(result)

        tree = etree.HTML(text)
        key = tree.xpath('//td')
        if key:
            msg = '恭喜你,找回用户名成功!您的用户名是: ' + key[0].text
        else:
            msg = ''
        result["msg"] = msg
    else:
        tree = etree.HTML(text)
        error_list = tree.xpath(
            '//ul[@id="user_retrivelgname_fm_error_info"]/li/span')
        add_ajax_error_json(result,
                            error_list[0].text if error_list else "未知错误")

    return JsonResponse(result)
コード例 #28
0
	def ship(self, computer_obj):
		try:
			computer_json = json_encode(computer_obj, unpicklable=True)
			payload = {
				'payload': computer_json
			}
			response = http_post(self._server_ship_address, data=payload, timeout=self.timeout)
			if response.status_code == 200:
				pass
			elif response.status_code == 202:
				logger.warning('The server ignored the shipped measurement')
			else:
				logger.warning(
					'Server responded with status code %i and message %s' % (response.status_code, response.text))
		except Exception as ex:
			logger.critical("Cannot ship to the server")
			logger.critical("Exception msg: [%s]" % str(ex))
コード例 #29
0
def zhengxin_reg2_request(request):
    """
       执行注册第二步
    """
    args = request.POST
    data = {"method": "saveUser",
            "userInfoVO.smsrcvtimeflag": "2",
            "userInfoVO.email": args["email"],
            "org.apache.struts.taglib.html.TOKEN": args["org.apache.struts.taglib.html.TOKEN"],
            "userInfoVO.loginName": args["loginName"],
            "userInfoVO.password": args["password"],
            "userInfoVO.confirmpassword": args["confirmpassword"],
            "userInfoVO.mobileTel": args["mobileTel"],
            "userInfoVO.verifyCode": args["verifyCode"],
            "tcId": args["tcId"],
            }
    params = urlencode(data, encoding="gb2312")

    headers = DEFAULT_REQUEST_HEADERS.copy()
    headers['User-Agent'] = USER_AGENT
    headers["Referer"] = "https://ipcrs.pbccrc.org.cn/userReg.do"
    kwargs = {"timeout": 6,
              "verify": False,
              "headers": headers,
              "cookies": request.session.get("req_cookie"),
              "params": params,
              }

    resp = http_post("https://ipcrs.pbccrc.org.cn/userReg.do", **kwargs)

    # TODO 容错
    ret_data = {}
    if resp.status_code == 200:
        text = resp.text
        error_msg = pattern_error_user.search(text)
        if error_msg:
            add_ajax_error_json(ret_data, error_msg.group(1))
        elif '注册成功' in text:
            add_ajax_ok_json(ret_data)
        else:
            add_ajax_error_json(ret_data, "注册失败")
    else:
        add_ajax_error_json(ret_data)

    return JsonResponse(ret_data)
コード例 #30
0
def get_response_by_requests_post(url,
                                  headers,
                                  data=None,
                                  cookie_str=None,
                                  cookie_jar=None):
    if cookie_str is not None:
        headers['Cookie'] = cookie_str

    kwargs = {
        "headers": headers,
        "timeout": ASK_TIMEOUT,
        "verify": False,
    }

    if cookie_jar is not None:
        kwargs["cookies"] = cookie_jar

    return http_post(url, data=data, **kwargs)
コード例 #31
0
def parse_spdb_credit_email_html(html_string, subject=""):
    bs_obj = BeautifulSoup(html_string, "lxml")

    bill_info = {}

    account_info_str = bs_obj.find("td").getText(strip=True)

    find_name = spdb_name_pattern.search(account_info_str)
    if find_name:
        bill_info['real_name'] = find_name.group(1)

    find_repayment = spdb_repayment_pattern.search(account_info_str)
    if find_repayment:
        bill_info['repayment'] = find_repayment.group(1).replace(",", "")

    find_due_date = spdb_due_date_pattern.search(account_info_str)
    if find_due_date:
        bill_info['due_date'] = find_due_date.group(1).replace("/", DATE_SEP)

    try:
        url1 = bs_obj.find('span',
                           text='点击').findParent("table").find('a').get('href')

        headers = SPDB_HEADERS.copy()
        r1 = http_get(url1, headers=headers)
        cookie_str = r1.headers.get('Set-Cookie')
        headers['Cookie'] = cookie_str
        url2 = 'https://ebill.spdbccc.com.cn/cloudbank-portal/myBillController/loadHomeData.action'

        r = http_post(url2, headers=headers)
        json_info = json_loads(r.text)
        bill_info['card_num'] = json_info.get('cardNo')
        bill_info['due_date'] = json_info.get('dueDate')
        bill_info['repayment'] = json_info.get('stmtAmt')
        bill_info['min_repayment'] = json_info.get('minPay')
        bill_info['credit_limit'] = json_info.get('creditLimit')
        bill_info['cash_limit'] = json_info.get('cashLimit')
        bill_info['bill_date'] = json_info.get('closeDate')
    except Exception:
        pass

    result = {'bill_info': bill_info, 'bill_detail': []}

    return result
コード例 #32
0
def hanvon_alicloudapi(pic):
    """识别率70%"""
    host = 'http://text.aliapi.hanvon.com'
    path = '/rt/ws/v1/ocr/text/recg'
    appcode = 'd6147d2ef06e4ce09ce029cae877daca'
    querys = 'code=74e51a88-41ec-413e-b162-bd031fe0407e'
    url = host + path + '?' + querys

    data = {'uid': "118.12.0.12",
            "lang": "chns",
            "color": "black",
            'image': pic
            }
    headers = {'Authorization': 'APPCODE ' + appcode,
               'Content-Type': 'application/json; charset=UTF-8',
               }

    response = http_post(url, data=json_dumps(data), headers=headers)
    return response.text