Exemple #1
0
 def post_custom(urlInfo, data=None):
     EasyHttp.resetHeaders()
     if 'headers' in urlInfo and urlInfo['headers']:
         EasyHttp.updateHeaders(urlInfo['headers'])
     try:
         if len(ips) == 0:
             response = EasyHttp.__session.request(method=urlInfo['method'],
                                                   url=urlInfo['url'],
                                                   data=data,
                                                   timeout=3,
                                                   allow_redirects=False)
         else:
             proxy_address = random.choice(ips)
             response = EasyHttp.__session.request(
                 method=urlInfo['method'],
                 url=urlInfo['url'],
                 data=data,
                 proxies={"http": "http://{}".format(proxy_address[0])},
                 timeout=3,
                 allow_redirects=False)
     except Exception as e:
         if ips:
             ips.remove(proxy_address)
         return None
     return response
Exemple #2
0
 def get_custom(urlInfo):
     try:
         if len(ips) == 0:
             response = EasyHttp.__session.request(method=urlInfo['method'],
                                                   url=urlInfo['url'],
                                                   timeout=3,
                                                   allow_redirects=False)
         else:
             proxy_address = random.choice(ips)
             response = EasyHttp.__session.request(
                 method=urlInfo['method'],
                 url=urlInfo['url'],
                 proxies={"http": "http://{}".format(proxy_address[0])},
                 timeout=3,
                 allow_redirects=False)
     except Exception as e:
         if ips:
             ips.remove(proxy_address)
         return None
     return response
Exemple #3
0
 def send(urlInfo, params=None, data=None, **kwargs):
     EasyHttp.resetHeaders()
     if 'headers' in urlInfo and urlInfo['headers']:
         EasyHttp.updateHeaders(urlInfo['headers'])
     try:
         if len(ips) == 0:
             response = EasyHttp.__session.request(method=urlInfo['method'],
                                                   url=urlInfo['url'],
                                                   params=params,
                                                   data=data,
                                                   timeout=3,
                                                   allow_redirects=False,
                                                   **kwargs)
         else:
             proxy_address = random.choice(ips)
             response = EasyHttp.__session.request(
                 method=urlInfo['method'],
                 url=urlInfo['url'],
                 params=params,
                 data=data,
                 #python3发现proxies写成{"https": "https://{}"}的形式没法访问,笑哭-_-
                 proxies={"http": "http://{}".format(proxy_address[0])},
                 timeout=3,
                 allow_redirects=False,
                 **kwargs)
         if response.status_code == requests.codes.ok:
             if 'response' in urlInfo:
                 if urlInfo['response'] == 'binary':
                     return response.content
                 if urlInfo['response'] == 'html':
                     response.encoding = response.apparent_encoding
                     return response.text
             return response.json()
     except:
         if ips:
             ips.remove(proxy_address)
     return None