Ejemplo n.º 1
0
def request(method, url, params=None, data=None, headers = FETCH_HEADERS, cookies=None, files=None, auth=None, timeout=None, allow_redirects=True, proxies=None, hooks=None, return_response=True, config=None, use_proxies = True):
    # This is the only thing we do
    if proxies is None and use_proxies:
        proxies = get_random_proxy(proxy_list = DEFAULT_PROXIES)
    if not proxies is None:
        auth = proxies['auth']
        del proxies['auth']
        
    
    s = session()
    kwargs = {
        'method' : method, 
        'url' : url,
        'params' : params,
        'data' : data,
        'headers' : headers,
        'cookies' : cookies,
        'files' : files,
        'auth' : auth,
        'timeout' : timeout,
        'allow_redirects' : allow_redirects,
        'proxies' : proxies,
        'hooks' : hooks,
        'return_response' : return_response,
        'config' : config,
    }
    
    return s.request(**kwargs)
Ejemplo n.º 2
0
 def __init__(self):
     self.host = None
     self.port = None
     self.callback = None
     self.bot_token = None
     self.handler = None
     self.session = sessions.session()
 def __init__(self, username, password):
     self.meter_session = sessions.session()
     self.meter_session.headers.update({
         'User-Agent':
         'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML,'
         ' like Gecko) Chrome/77.0.3865.90 Safari/537.36',
         'Accept-Encoding':
         'gzip, deflate',
         'Accept':
         'application/json, text/plain, */*',
         'Connection':
         'keep-alive',
         'Origin':
         api_config['API_ENDPOINTS']['PORTAL_BASE'],
         'Sec-Fetch-Mode':
         'cors',
         'Content-Type':
         'application/json;charset=UTF-8'
     })
     self.username = username
     self.password = password
     self.meter_session_cookies = None
     self.meter_auth_token = None
     self.meter_details = None
     self.set_cookies()
     print("Created Meter Session Manager Object")
Ejemplo n.º 4
0
    def __init__(self, access_token):
        """
        starts a new connection to dropbox

        :param str access_token: dbx access token
        """
        self._access_token = access_token
        self._session = session()
        self._dbx = Dropbox(oauth2_access_token=self._access_token, session=self._session)
Ejemplo n.º 5
0
 def __init__(self, core, tokenUrl, appIdFn):
     super(TokenClass, self).__init__(core)
     self.tokenUrl, self.appIdFn = tokenUrl, appIdFn
     self._session = session()
     self._session.verify = False
     self._autoMaintain = False
     self._tokenFunction = self.token_function_producer()
     self._syncTokenFunction = self.token_function_producer(True)
     self._accessTokenFunction = self.access_token_producer()
     self._syncAccessTokenFunction = self.access_token_producer(True)
Ejemplo n.º 6
0
 def __init__(self):
     self.cookie = get_secrets('COOKIES')
     self.session = session()
     self.header = {
         "Content-Type": "application/x-www-form-urlencoded",
         "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) "
                       "Chrome/88.0.4324.182 Safari/537.36 Edg/88.0.705.81",
         "referer": "https://www.douyu.com",
         "Cookie": self.cookie
     }
Ejemplo n.º 7
0
 def __init__(self, core, tokenUrl, appIdFn):
     super(TokenClass, self).__init__(core)
     self.tokenUrl, self.appIdFn = tokenUrl, appIdFn
     self._session = session()
     self._session.verify = False
     self._autoMaintain = False
     self._tokenFunction = self.token_function_producer()
     self._syncTokenFunction = self.token_function_producer(True)
     self._accessTokenFunction = self.access_token_producer()
     self._syncAccessTokenFunction = self.access_token_producer(True)
Ejemplo n.º 8
0
def rebootzone(ipAddress):
    session = RequestsSessions.session()
    session.keep_alive = False
    session.mount('http://', RequestsAdapters.HTTPAdapter(max_retries=5))
    rebooturl = "http://" + ipAddress + ":1400/reboot"
    rebootget = session.get(rebooturl, timeout=5)
    rebootresponse = ElementTree.fromstring(rebootget.text)
    for body in rebootresponse:
        csrftoken = body.find('form').find('input').attrib["value"]
        session.post(rebooturl, {"csrfToken": csrftoken}, timeout=5)
    return
Ejemplo n.º 9
0
 def __init__(self,
              apiUrl,
              apiKey,
              proxies=None,
              verify_ssl=False,
              ssl_cert=None):
   if proxies is None:
     proxies = {}
   self.apiUrl = '{0}/REST/0.3.0'.format(apiUrl)
   self.apiKey = apiKey
   self.proxies = proxies
   self.verify_ssl = verify_ssl
   self.ssl_cert = ssl_cert
   self.session = session()
Ejemplo n.º 10
0
def upfile(username, password, zip_name=None):
    "上传"

    print "正在登录115.com"
    import re
    from hashlib import md5
    from requests import sessions, api
    HEADERS = {
        "user_agent": "User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_4) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/22.0.1207.1 Safari/537.1",
    }
    s = sessions.session(headers=HEADERS)
    resp = s.request("POST",
            "https://passport.115.com/?ac=login",
            data={
                "login[account]": username,
                "login[passwd]": password,
                "login[time]": "true"
            })
    resp = s.request("GET", "http://115.com")
    try:
        user_cookie = re.search("var USER_COOKIE = [\"']([^'\"]+)[\"'];", resp.text).group(1)
        user_rsa1 = re.search("Core.CONFIG.FUpRsa1 = [\"']([^\"']+)[\"'];", resp.text).group(1)
        user_rsa2 = re.search("Core.CONFIG.FUpRsa2 = [\"']([^\"']+)[\"'];", resp.text).group(1)
    except AttributeError:
        print "Error Account.."

    token_time = str(int(time.time()*1000))
    file_size = os.path.getsize(zip_name)
    token = md5(user_rsa1 + user_rsa2 + str(file_size) + token_time + user_rsa2 + user_rsa1).hexdigest()
    print "正在上传: %s 文件大小: %s 请稍后..." % (zip_name, file_size)
    resp = api.post("http://vipup.u.115.com/upload",
            data={
                "FileName": zip_name,
                "cid": "2156432", #U115 directory
                "cookie": user_cookie,
                "aid": "1",
                "token": token,
                "time": token_time,
                "Upload": "Submit Query",
            }, files={
                "Filedata": (zip_name.decode("u8"), open(zip_name)),
            }, headers={
                "user-agent": "Adobe Flash Player 11",
                "x-flash-version": "11,3,300,265",
            })
    
    print "上传成功"
    print resp.json
Ejemplo n.º 11
0
def enumeratezones(ipaddress):
    zoneurl = "http://" + ipaddress + ":1400/support/review"
    session = RequestsSessions.session()
    session.keep_alive = False
    session.mount('http://', RequestsAdapters.HTTPAdapter(max_retries=5))
    zoneget = session.get(zoneurl, timeout=5)
    zones = list()

    # Build and traverse XML tree for support page
    zpnetworkinfo = ElementTree.fromstring(zoneget.content)
    for zpsupportinfo in zpnetworkinfo.iter('ZPSupportInfo'):
        zpinfo = zpsupportinfo.find('ZPInfo')
        zonename = zpinfo.find('ZoneName').text
        ipaddress = zpinfo.find('IPAddress').text
        ethernetcount = 0
        wirelesscount = 0

        #Get spanning tree information to determine the order to reboot devices.
        commands = zpsupportinfo.iter("Command")
        for command in commands:
            if command.attrib["cmdline"].startswith('/usr/sbin/brctl showstp'):
                # Count active ethernet interfaces
                pattern = re.compile(r'eth\d.*?state.*?$',
                                     re.DOTALL | re.MULTILINE)
                matches = pattern.finditer(command.text)
                if matches is not None:
                    for match in matches:
                        result = match.group()
                        pattern = re.compile(r'forwarding', re.DOTALL)
                        match = pattern.search(result)
                        if match is not None: ethernetcount += 1
                # Count active wireless interfaces
                pattern = re.compile(r'ath\d.*?state.*?$',
                                     re.DOTALL | re.MULTILINE)
                matches = pattern.finditer(command.text)
                if matches is not None:
                    for match in matches:
                        result = match.group()
                        pattern = re.compile(r'forwarding', re.DOTALL)
                        match = pattern.search(result)
                        if match is not None: wirelesscount += 1
        rebootorder = 0
        if wirelesscount != 0:
            rebootorder = 1000 * ethernetcount + wirelesscount
        zone = [zonename, ipaddress, rebootorder]
        zones.append(zone)
        zones = sorted(zones, key=lambda weight: weight[2])
    return zones
Ejemplo n.º 12
0
    def __init__(self):
        self.s = sessions.session()
        full_key = cKey + ':' + cSecret
        encoded_bytes = b64encode(full_key.encode("utf-8"))
        final_key = str(encoded_bytes, "utf-8")

        auth_headers = {
            'Authorization': 'Basic ' + final_key,
            'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'
        }
        auth_params = {'grant_type': 'client_credentials'}
        resp = self.s.post('https://api.twitter.com/oauth2/token',
                           headers=auth_headers,
                           data=auth_params)
        auth_response = json.loads(resp.content)
        self.token = auth_response['access_token']
Ejemplo n.º 13
0
    def chunk(self, path, filename, size, offset=0):
        """
        return one chunk of file

        :param str path: path on server
        :param str filename: name of file
        :param int size: chunk-size
        :param int offset: bits from the beginning
        :return: tuple(File obj, content)
        """
        p_session = session()
        dbx_p = Dropbox(oauth2_access_token=self._access_token, headers={
            "Range": "bytes=" + str(offset) + "-" + str(offset + size - 1)}, session=p_session)  # fetch chunks from dropbox
        meta, response = dbx_p.files_download(path+"/"+filename)
        f = File(meta.name, meta.path_lower, meta.client_modified, meta.client_modified)
        p_session.close()
        return f, response.content
Ejemplo n.º 14
0
 def login(self) -> session:
     """如果登录成功那么返回session否则返回None并且打印失败信息"""
     self.s = session()
     loginStatus = self.s.post(self.loginUrl,
                               data=self.loginInfo,
                               headers=self.headers)
     if loginStatus.status_code == 200:
         if 'errline' in loginStatus.json()['data']:
             print(loginStatus.json()['msg'])
             return None
         elif loginStatus.json()['msg'] == "":
             print("登录成功")
             return self.s
         else:
             print("未知情况")
             print(loginStatus.json())
             return None
     else:
         return None
Ejemplo n.º 15
0
	def __init__(self, *args, **kwargs):
		self.conn = pymysql.connect(
			host='10.44.60.141',
			# host='101.200.166.12',
			user='******',
			password='******',
			db='spider',
			charset='utf8mb4',
			cursorclass=pymysql.cursors.DictCursor,
			use_unicode=True
		)
		self.cursor = self.conn.cursor()
		self.ua = UserAgent()
		# self.cookies = [
		# 	'user_trace_token=20170612170648-026cfbd0f39d4330b02cf404bac6d999; Hm_lvt_4233e74dff0ae5bd0a3d81c6ccf756e6=1497258409,1497577951; LGUID=20170612170650-7898a127-4f4e-11e7-9ab4-5254005c3644; _ga=GA1.2.109776163.1497258409; index_location_city=%E5%85%A8%E5%9B%BD; _gid=GA1.2.722219593.1497427964; SEARCH_ID=8ed5770ccb9d4b99b174c1d9e1b93fdd; JSESSIONID=ABAAABAABEEAAJA1B1DFAE62C3164498D1AAA9F6FDFA840; Hm_lpvt_4233e74dff0ae5bd0a3d81c6ccf756e6=1497594024; LGRID=20170616142030-e5896203-525b-11e7-9c6d-5254005c3644; TG-TRACK-CODE=index_search; LGSID=20170616135506-5900b1fa-5258-11e7-9bc5-525400f775ce',
		# 	'user_trace_token=20170611162631-ac0e66cb-4e7f-11e7-83ee-525400f775ce; LGUID=20170611162631-ac0e6aae-4e7f-11e7-83ee-525400f775ce; fromsite="localhost:63342"; JSESSIONID=ABAAABAABEEAAJABF9E692B8A110EAC1E5B8D41DCB395EF; _gat=1; PRE_UTM=; PRE_HOST=; PRE_SITE=; PRE_LAND=https%3A%2F%2Fwww.lagou.com%2F; _putrc=4F9D5E0356A7F682; login=true; unick=%E5%AD%99%E7%AB%8B%E5%BB%BA; showExpriedIndex=1; showExpriedCompanyHome=1; showExpriedMyPublish=1; hasDeliver=1; TG-TRACK-CODE=index_search; _gid=GA1.2.805528246.1497530341; _ga=GA1.2.200265071.1497169588; LGSID=20170617125231-c53b4db5-5318-11e7-9c6f-5254005c3644; LGRID=20170617125253-d279455a-5318-11e7-9cb7-525400f775ce; Hm_lvt_4233e74dff0ae5bd0a3d81c6ccf756e6=1497257843,1497270178,1497439331,1497675144; Hm_lpvt_4233e74dff0ae5bd0a3d81c6ccf756e6=1497675166; SEARCH_ID=c420f95450ed43b1aac4e94524e157aa; index_location_city=%E5%8C%97%E4%BA%AC',
		# 	'user_trace_token=20170611162631-ac0e66cb-4e7f-11e7-83ee-525400f775ce; LGUID=20170611162631-ac0e6aae-4e7f-11e7-83ee-525400f775ce; fromsite="localhost:63342"; JSESSIONID=ABAAABAABEEAAJABF9E692B8A110EAC1E5B8D41DCB395EF; _putrc=4F9D5E0356A7F682; login=true; unick=%E5%AD%99%E7%AB%8B%E5%BB%BA; showExpriedIndex=1; showExpriedCompanyHome=1; showExpriedMyPublish=1; hasDeliver=1; TG-TRACK-CODE=index_search; _gid=GA1.2.805528246.1497530341; _ga=GA1.2.200265071.1497169588; Hm_lvt_4233e74dff0ae5bd0a3d81c6ccf756e6=1497257843,1497270178,1497439331,1497675144; Hm_lpvt_4233e74dff0ae5bd0a3d81c6ccf756e6=1497675187; LGRID=20170617125314-df4f1bb2-5318-11e7-9cb8-525400f775ce; SEARCH_ID=5220eaf2c7984c2a82cb444855c488f6; index_location_city=%E5%8C%97%E4%BA%AC',
		# 	'user_trace_token=20170612170648-026cfbd0f39d4330b02cf404bac6d999; Hm_lvt_4233e74dff0ae5bd0a3d81c6ccf756e6=1497258409,1497577951; LGUID=20170612170650-7898a127-4f4e-11e7-9ab4-5254005c3644; _ga=GA1.2.109776163.1497258409; index_location_city=%E5%85%A8%E5%9B%BD; _gid=GA1.2.722219593.1497427964; SEARCH_ID=3a924c638aad4c7fb4b7ae36b26d440e; JSESSIONID=ABAAABAABEEAAJA1B1DFAE62C3164498D1AAA9F6FDFA840; Hm_lpvt_4233e74dff0ae5bd0a3d81c6ccf756e6=1497678584; LGRID=20170617134952-c834c774-5320-11e7-9c70-5254005c3644; TG-TRACK-CODE=index_search; _gat=1; LGSID=20170617134948-c5c76755-5320-11e7-9cd0-525400f775ce; PRE_UTM=; PRE_HOST=; PRE_SITE=; PRE_LAND=https%3A%2F%2Fpassport.lagou.com%2Flogin%2Flogin.html%3Fmsg%3Dvalidation%26uStatus%3D2%26clientIp%3D36.110.41.42'
		# 	'user_trace_token=20170611162631-ac0e66cb-4e7f-11e7-83ee-525400f775ce; LGUID=20170611162631-ac0e6aae-4e7f-11e7-83ee-525400f775ce; fromsite="localhost:63342"; JSESSIONID=ABAAABAABEEAAJABF9E692B8A110EAC1E5B8D41DCB395EF; _putrc=4F9D5E0356A7F682; login=true; unick=%E5%AD%99%E7%AB%8B%E5%BB%BA; showExpriedIndex=1; showExpriedCompanyHome=1; showExpriedMyPublish=1; hasDeliver=1; TG-TRACK-CODE=index_search; _ga=GA1.2.200265071.1497169588; _gid=GA1.2.805528246.1497530341; LGSID=20170617134823-935e1867-5320-11e7-9c70-5254005c3644; PRE_UTM=; PRE_HOST=; PRE_SITE=https%3A%2F%2Fwww.lagou.com%2Fjobs%2Flist_%2520%25E5%258C%2597%25E4%25BA%25AC%25E9%2598%25BF%25E5%25B0%2594%25E6%25B3%2595%25E6%258A%2595%25E8%25B5%2584%25E9%259B%2586%25E5%259B%25A2%25E6%259C%2589%25E9%2599%2590%25E5%2585%25AC%25E5%258F%25B8%3Fcity%3D%25E5%258C%2597%25E4%25BA%25AC%26cl%3Dfalse%26fromSearch%3Dtrue%26labelWords%3D%26suginput%3D; PRE_LAND=https%3A%2F%2Fwww.lagou.com%2Fjobs%2Flist_%2520%25E5%258C%2597%25E4%25BA%25AC%25E4%25B8%25AD%25E7%2594%25B5%25E5%258D%2593%25E8%2583%25BD%25E6%2595%2599%25E8%2582%25B2%25E7%25A7%2591%25E6%258A%2580%25E6%259C%2589%25E9%2599%2590%25E5%2585%25AC%25E5%258F%25B8%3Fcity%3D%25E5%258C%2597%25E4%25BA%25AC%26cl%3Dfalse%26fromSearch%3Dtrue%26labelWords%3D%26suginput%3D; LGRID=20170617134823-935e1a54-5320-11e7-9c70-5254005c3644; Hm_lvt_4233e74dff0ae5bd0a3d81c6ccf756e6=1497257843,1497270178,1497439331,1497675144; Hm_lpvt_4233e74dff0ae5bd0a3d81c6ccf756e6=1497678496; SEARCH_ID=91273cccf7db411ba100db9e6a936bc5; index_location_city=%E5%8C%97%E4%BA%AC',
		# 	'user_trace_token=20170611162631-ac0e66cb-4e7f-11e7-83ee-525400f775ce; LGUID=20170611162631-ac0e6aae-4e7f-11e7-83ee-525400f775ce; fromsite="localhost:63342"; JSESSIONID=ABAAABAABEEAAJABF9E692B8A110EAC1E5B8D41DCB395EF; _putrc=4F9D5E0356A7F682; login=true; unick=%E5%AD%99%E7%AB%8B%E5%BB%BA; showExpriedIndex=1; showExpriedCompanyHome=1; showExpriedMyPublish=1; hasDeliver=1; TG-TRACK-CODE=index_search; PRE_UTM=; PRE_HOST=; PRE_SITE=https%3A%2F%2Fwww.lagou.com%2Fjobs%2Flist_%2520%25E5%258C%2597%25E4%25BA%25AC%25E9%2598%25BF%25E5%25B0%2594%25E6%25B3%2595%25E6%258A%2595%25E8%25B5%2584%25E9%259B%2586%25E5%259B%25A2%25E6%259C%2589%25E9%2599%2590%25E5%2585%25AC%25E5%258F%25B8%3Fcity%3D%25E5%258C%2597%25E4%25BA%25AC%26cl%3Dfalse%26fromSearch%3Dtrue%26labelWords%3D%26suginput%3D; PRE_LAND=https%3A%2F%2Fwww.lagou.com%2Fjobs%2Flist_%2520%25E5%258C%2597%25E4%25BA%25AC%25E4%25B8%25AD%25E7%2594%25B5%25E5%258D%2593%25E8%2583%25BD%25E6%2595%2599%25E8%2582%25B2%25E7%25A7%2591%25E6%258A%2580%25E6%259C%2589%25E9%2599%2590%25E5%2585%25AC%25E5%258F%25B8%3Fcity%3D%25E5%258C%2597%25E4%25BA%25AC%26cl%3Dfalse%26fromSearch%3Dtrue%26labelWords%3D%26suginput%3D; _gid=GA1.2.805528246.1497530341; _ga=GA1.2.200265071.1497169588; Hm_lvt_4233e74dff0ae5bd0a3d81c6ccf756e6=1497257843,1497270178,1497439331,1497675144; Hm_lpvt_4233e74dff0ae5bd0a3d81c6ccf756e6=1497679473; LGSID=20170617134823-935e1867-5320-11e7-9c70-5254005c3644; LGRID=20170617140441-da0efd17-5322-11e7-9c70-5254005c3644; SEARCH_ID=24cd7522dd974eb997ba288cbb648b7f; index_location_city=%E5%8C%97%E4%BA%AC',
		# 	'user_trace_token=20170612170648-026cfbd0f39d4330b02cf404bac6d999; Hm_lvt_4233e74dff0ae5bd0a3d81c6ccf756e6=1497258409,1497577951; LGUID=20170612170650-7898a127-4f4e-11e7-9ab4-5254005c3644; _ga=GA1.2.109776163.1497258409; index_location_city=%E5%85%A8%E5%9B%BD; _gid=GA1.2.722219593.1497427964; SEARCH_ID=ef064afaad504da286fff87b92b32359; JSESSIONID=ABAAABAABEEAAJA1B1DFAE62C3164498D1AAA9F6FDFA840; Hm_lpvt_4233e74dff0ae5bd0a3d81c6ccf756e6=1497678608; LGRID=20170617135014-d5c1980f-5320-11e7-9cd0-525400f775ce; TG-TRACK-CODE=index_search; LGSID=20170617134948-c5c76755-5320-11e7-9cd0-525400f775ce; PRE_UTM=; PRE_HOST=; PRE_SITE=; PRE_LAND=https%3A%2F%2Fpassport.lagou.com%2Flogin%2Flogin.html%3Fmsg%3Dvalidation%26uStatus%3D2%26clientIp%3D36.110.41.42',
		# ]

		self.headers = {
			"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
			"HOST": "www.lagou.com",
			"Referer": "https://www.lagou.com/jobs/list_%E4%B8%8A%E6%B5%B7%E5%BE%B7%E5%A8%81%E4%BC%81%E4%B8%9A%E5%8F%91%E5%B1%95%E8%82%A1%E4%BB%BD%E6%9C%89%E9%99%90%E5%85%AC%E5%8F%B8?city=%E4%B8%8A%E6%B5%B7&cl=true&fromSearch=true&labelWords=&suginput=",
			'User-Agent': self.ua.random,
			'X-Anit-Forge-Code': "0",
			'X-Anit-Forge-Token': "None",
			'X-Requested-With': "XMLHttpRequest",
			'Accept-Encoding': "gzip, deflate, br",
			# 'Cookie': random.choice(self.cookies)
		}
		# proxyMeta = "http://*****:*****@proxy.abuyun.com:9020"
		# self.proxies = {
		# 	"http": proxyMeta,
		# 	"https": proxyMeta,
		# }
		self.s = session()
Ejemplo n.º 16
0
from tornado import gen

from ..requests import requests
from itchatmp.config import COROUTINE
from itchatmp.server import WechatServer
from itchatmp.utils import retry
from itchatmp.returnvalues import ReturnValue

__all__ = ['update_access_token_producer', 'access_token', 'filter_request']

logger = logging.getLogger('itchatmp')

__server = WechatServer(None, None, None)
__AUTO_MAINTAIN = False
__serverList = None
__session = session()
__session.verify = False
get = __session.get


def auto_maintain_thread(firstCallResult=None, tokenUrl=None, appIdFn=None):
    r = firstCallResult or update_access_token_producer(
        tokenUrl, appIdFn, True)()
    if not r:
        __server.ioLoop.call_later((datetime.replace(
            datetime.now() + timedelta(days=1), hour=0, minute=5, second=0) -
                                    datetime.now()).seconds,
                                   maintain_access_token, None, tokenUrl,
                                   appIdFn)
    else:
        __server.ioLoop.call_later(r['expires_in'] - 30, maintain_access_token,
Ejemplo n.º 17
0
import logging

from requests import sessions
from requests.auth import HTTPBasicAuth

from track.utils import remove_trailing_slash
from track.version import VERSION
from track.const import DEFAULT_HOST

_session = sessions.session()
logger = logging.getLogger('interakt')


def post(api_key, host=None, path=None, body=None, timeout=10):
    """Post the msg to the API"""
    auth = HTTPBasicAuth(username=api_key, password="")
    headers = {
        'Content-Type': 'application/json',
        'User-Agent': f'interakt-track-python/{VERSION}'
    }
    url = remove_trailing_slash(host or DEFAULT_HOST) + path
    logger.debug(f'Making request: {body}')
    response = _session.post(url=url,
                             headers=headers,
                             auth=auth,
                             json=body,
                             timeout=timeout)
    if 200 <= response.status_code <= 299:
        logger.debug("Data uploaded successfully")
        return response
Ejemplo n.º 18
0
def wwc_check(person, verbose=False, nocache=False):

    if person is None or person.ident is None or person.name is None:
        return WWCCheckResult(WWCCheckStatus.NONE,
                              'Skipping - invalid person {}'.format(person),
                              None)

    ident = person.ident
    if not nocache and ident in _wwc_check_cache:
        return _wwc_check_cache[ident]
    if person.checkname is not None:
        name = ensure_text(person.checkname)
        if verbose:
            print('[Using {} for name instead of {}]'.format(
                person.checkname, person.name))
    else:
        name = ensure_text(person.name)
    wwcn = person.number

    if ident == 0:
        _wwc_check_cache[ident] = WWCCheckResult(WWCCheckStatus.UNKNOWN,
                                                 'Skipping - Placeholder ID',
                                                 None)
        return _wwc_check_cache[ident]

    if person.dob is not None and is_under18(person.dob):
        _wwc_check_cache[ident] = WWCCheckResult(
            WWCCheckStatus.UNDER18,
            'Skipping - Under 18 (DoB: {})'.format(person.dob), None)
        return _wwc_check_cache[ident]

    if wwcn is None or wwcn == '':
        _wwc_check_cache[ident] = WWCCheckResult(
            WWCCheckStatus.EMPTY, 'Skipping - Empty WWC Number', None)
        return _wwc_check_cache[ident]

    m = _wwc_number_pattern.match(wwcn)

    if m is None:
        if wwcn.startswith('VIT'):
            _wwc_check_cache[ident] = WWCCheckResult(
                WWCCheckStatus.TEACHER,
                'Skipping - Victorian Teacher ({})'.format(wwcn), None)
        else:
            _wwc_check_cache[ident] = WWCCheckResult(
                WWCCheckStatus.BADNUMBER,
                'Skipping - Bad WWC Number ({})'.format(wwcn), None)
        return _wwc_check_cache[ident]

    cardnumber = m.group(1).upper()
    lastname = '%20'.join(name.split()[1:])
    postdata = dict(_wwc_post_data)
    postdata['cardnumber'] = cardnumber
    postdata['lastname'] = lastname

    with _wwc_check_lock:
        # based on: https://stackoverflow.com/a/61643770/2130789
        global _wwc_check_session
        if _wwc_check_session is None:
            _wwc_check_session = session()
            _wwc_check_session.mount('https://', _TLSAdapter())
        try:
            res = _wwc_check_session.post(_wwc_url, postdata)
        except BaseException as e:
            _wwc_check_cache[ident] = WWCCheckResult(
                WWCCheckStatus.FAILED,
                'Exception during Web Transaction: {}'.format(e), None)
            return _wwc_check_cache[ident]

    if res.status_code != 200:
        _wwc_check_cache[ident] = WWCCheckResult(
            WWCCheckStatus.FAILED,
            'Web Transaction Failed with status {}!'.format(res.status_code),
            None)
        return _wwc_check_cache[ident]
    contents = res.text

    for line in contents.splitlines():

        m = _wwc_result_pattern.match(line)
        if not m:
            continue

        success, expired, notvalid = m.group(2, 6, 7)

        if expired:
            if verbose:
                print('expired response = {}'.format(expired))
            _wwc_check_cache[ident] = WWCCheckResult(
                WWCCheckStatus.EXPIRED,
                'WWC Number ({}) has Expired'.format(wwcn), None)
            return _wwc_check_cache[ident]

        if notvalid:
            if verbose:
                print('notvalid response = {}'.format(notvalid))
            _wwc_check_cache[ident] = WWCCheckResult(
                WWCCheckStatus.EXPIRED,
                'WWC Number ({}) with Lastname ({}) NOT VALID'.format(
                    wwcn, lastname), None)
            return _wwc_check_cache[ident]

        if success is not None:
            if verbose:
                print('success response = {}'.format(success))
            _wwc_check_cache[ident] = WWCCheckResult(
                WWCCheckStatus.SUCCESS, 'WWC Check Succeeded',
                date(*time.strptime('-'.join(m.group(5, 4, 3)), '%Y-%b-%d')
                     [:3]))
            return _wwc_check_cache[ident]

    if verbose:
        print('bad response = {}'.format(contents))
    _wwc_check_cache[ident] = WWCCheckResult(
        WWCCheckStatus.BADRESPONSE, 'WWC Check Service returned BAD response',
        None)
    return _wwc_check_cache[ident]
Ejemplo n.º 19
0
 def __init__(self, core, tokenUrl):
     super().__init__(core)
     self.tokenUrl = tokenUrl
     self._session = session()
     self._session.verify = False
     self._accessTokenFunction = self.access_token_producer()
Ejemplo n.º 20
0
import requests
from bs4 import BeautifulSoup
from requests.sessions import session
import time
s = session()

headers = {
    "Accept":
    "*/*",
    "Accept-Language":
    "zh-CN,zh;q=0.9",
    "Content-Type":
    "application/x-www-form-urlencoded",
    "Host":
    "passport.weibo.cn",
    "Origin":
    "https://passport.weibo.cn",
    "Referer":
    "https://passport.weibo.cn/signin/login?entry=mweibo&res=wel&wm=3349&r=https%3A%2F%2Fm.weibo.cn%2F",
    "Sec-Fetch-Dest":
    "empty",
    "Sec-Fetch-Mode":
    "cors",
    "Sec-Fetch-Site":
    "same-origin",
    "User-Agent":
    "Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.132 Mobile Safari/537.3"
}

loginUrl = "https://passport.weibo.cn/sso/login"  #post
temp = "https://m.weibo.cn/u/5644764907?uid=5644764907&t=0&luicode=10000011&lfid=100103type%3D1%26q%3D%E6%9D%A8%E8%B6%85%E8%B6%8A"  #get
Ejemplo n.º 21
0
    def find_m3u8_playlist(itunes_url: str, user_agent: str = None) -> MovieData:
        """
        Scrape an iTunes page to find the URL of the M3U8 playlist.

        Args:
            itunes_url (str): URL of an iTunes movie page to scrape.
            user_agent (str, optional): User-Agent string to use for scraping. Defaults to None.

        Raises:
            InvalidURL: An inavlid iTunes URL was provided.
            ConnectionError: A connection error occurred while trying to request the page.
            HTTPError: An error while trying to download m3u8 playlist data.
            PageLoadError: The page did not load properly.

        Returns:
            MovieData: A MovieData (NamedTuple) object with movie's name, and an M3U8 object of the playlist
            if the playlist is found. None otherwise.
        """
        # Check whether URL is valid
        if re.match(ITUNES_STORE_REGEX, itunes_url) is None:
            raise InvalidURL(f"{itunes_url} is not a valid iTunes movie URL.")

        site_page: BeautifulSoup = BeautifulSoup(session().get(itunes_url, headers={"User-Agent": user_agent}).text, "lxml")
        movie_metadata: Union[Tag, NavigableString, None] = site_page.find("script", attrs={"name": "schema:movie", "type": 'application/ld+json'})

        if not isinstance(movie_metadata, Tag):
            raise PageLoadError("The page did not load properly.")

        # Convert to dictionary structure
        movie_metadata_dict: dict = json.loads(str(movie_metadata.contents[0]).strip())

        media_type: str = movie_metadata_dict['@type']
        movie_title: str = html.unescape(movie_metadata_dict['name'])

        if media_type != "Movie":
            raise InvalidURL("The provided iTunes URL is not for a movie.")

        # Scrape a dictionary on the webpage for playlists data
        playlists_data_tag: Union[Tag, NavigableString, None] = site_page.find("script", attrs={"id": "shoebox-ember-data-store", "type": "fastboot/shoebox"})

        # fastboot/shoebox data could not be found
        if not isinstance(playlists_data_tag, Tag):
            raise PageLoadError("fastboot/shoebox data could not be found.")

        # Convert to dictionary structure
        playlists_data: dict[str, dict] = json.loads(str(playlists_data_tag.contents[0]).strip())

        # Loop safely over different structures to find a matching playlist
        for key in playlists_data.keys():
            if isinstance(playlists_data[key].get("included"), list):
                for item in playlists_data[key]["included"]:
                    if (isinstance(item.get("type"), str) and item["type"] == "offer" and
                            isinstance(item.get("attributes"), dict) and
                            isinstance(item["attributes"].get("assets"), list) and
                            len(item["attributes"]["assets"]) > 0 and
                            isinstance(item["attributes"]["assets"][0], dict) and
                            isinstance(item["attributes"]["assets"][0].get("hlsUrl"), str)):
                        m3u8_url: str = item["attributes"]["assets"][0]["hlsUrl"]

                        try:
                            playlist: M3U8 = m3u8.load(m3u8_url)

                        # If m3u8 playlist is invalid, skip it
                        except ValueError:
                            continue

                        except HTTPError:
                            continue

                        # Assure playlist is for the correct movie
                        if iSubRip.is_playlist_valid(playlist, movie_title):
                            return MovieData(movie_title, playlist)

        return MovieData(movie_title, None)
Ejemplo n.º 22
0
# cookie
import requests
#1.登录
login = requests.post(url='http://test.lemonban.com/futureloan/mvc/api/member/login',data={'mobilephone':'13413766443','pwd':'213465'})
res = login.content.decode('utf8')

#充值  登录之后,自动携带cookie去请求接口
from requests.sessions import session

recharge = session().post('http://test.lemonban.com/futureloan/mvc/api/member/recharge',{'mobilephone':'13413766443','amount':'100'})
print(recharge.json())

print(res)