本文整理汇总了Python中httplib.CannotSendRequest方法的典型用法代码示例。如果您正苦于以下问题:Python httplib.CannotSendRequest方法的具体用法?Python httplib.CannotSendRequest怎么用?Python httplib.CannotSendRequest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类httplib
的用法示例。
在下文中一共展示了httplib.CannotSendRequest方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _http_req
# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import CannotSendRequest [as 别名]
def _http_req(self, method, path, payload=None, retries=2):
serialized_payload = json.dumps(payload) if payload is not None else None
try:
self._http.request(method, path, serialized_payload, self._COMMON_HEADERS)
http_response = self._http.getresponse()
except (http.BadStatusLine, http.CannotSendRequest):
self._http = http.HTTPConnection(self._host)
if retries > 0:
return self._http_req(method, path, payload, retries-1)
self._handle_error(self, None, Connection.OperationalError, "Connection has expired.")
if not http_response.status in [200, 201]:
message = "Server returned unexpected response: " + ustr(http_response.status) + ustr(http_response.read())
self._handle_error(self, None, Connection.OperationalError, message)
return http_response
示例2: save_html
# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import CannotSendRequest [as 别名]
def save_html(driver, filename, path):
make_folder(path)
html_path = path + str(filename) + ".html"
f = open(html_path, "w")
done = False
while done is False:
try:
f.write(driver.page_source.encode("UTF-8"))
done = True
except CannotSendRequest:
done = False
time.sleep(1)
except (TimeoutError, TimeoutException):
logging.warning("save_html() timed out")
return "Timed-out"
f.close()
return "No Error"
示例3: __conn_request
# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import CannotSendRequest [as 别名]
def __conn_request(self, http_verb, urn, params):
"""
Wrapper to request/response of httplib's context, reload a
connection if presume that error will occurs and returns the response
"""
try:
self.__conn.request(http_verb, urn, params, self.headers)
except CannotSendRequest:
self.__reload_conn()
self.__conn.request(http_verb, urn, params, self.headers)
try:
response = self.__conn.getresponse()
except (IOError, BadStatusLine):
self.__reload_conn()
self.__conn.request(http_verb, urn, params, self.headers)
response = self.__conn.getresponse()
return response
示例4: save_screenshot
# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import CannotSendRequest [as 别名]
def save_screenshot(driver, filename, path):
make_folder(path)
ss_path = path + str(filename) + ".png"
done = False
while done is False:
try:
driver.save_screenshot(ss_path)
done = True
except CannotSendRequest:
done = False
time.sleep(1)
except (TimeoutError, TimeoutException):
logging.warning("save_screenshot() timed out")
return "Timed-out"
return "No Error"
示例5: abort_load
# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import CannotSendRequest [as 别名]
def abort_load(driver, display, tor, tor_call, display_mode, capture_path, process_tag, port, exits):
logging.debug("Aborting page load...")
not_closed = True
while not_closed:
try:
driver, display, tor_call = restart_driver(driver, display, tor, tor_call, display_mode, capture_path,
port, process_tag, exits)
not_closed = False
time.sleep(10)
except CannotSendRequest:
not_closed = True
return driver, display
示例6: __reload_conn
# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import CannotSendRequest [as 别名]
def __reload_conn(self):
"""
Wrapper to keep TCP connection ESTABLISHED. Rather the connection go to
CLOSE_WAIT and raise errors CannotSendRequest or the server reply with
empty and it raise BadStatusLine
"""
self.__conn = HTTPSConnection(config.API_HOSTNAME) # reload
self.__conn.timeout = 10
示例7: _prefetch_in_background
# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import CannotSendRequest [as 别名]
def _prefetch_in_background(self, n, amount, offset):
headers = {
'Range': "bytes=" + str(max(offset, 0)) + "-" + str(
min((offset + amount) - 1, self.length) # noqa
),
}
self._wait_on_prefetch_connection(n)
while not self.pconn_terminated[n]:
try:
self.pconn[n].request(
"GET", self.parsed_url.path, headers=headers)
break
except CannotSendRequest:
sleep(1)
while not self.pconn_terminated[n]:
try:
res = self.pconn[n].getresponse()
break
except ResponseNotReady:
# Since we are sharing the connection wait for this to be
# ready
sleep(1)
if self.pconn_terminated[n]:
self._unwait_on_prefetch_connection(n)
return
else:
self._unwait_on_prefetch_connection(n)
if not(res.status >= 200 and res.status <= 299):
# Check for a valid status from the server
return
data = bytearray(res.length)
i = 0
for piece in iter(lambda: res.read(1024), bytes('')):
if not getattr(threading.currentThread(), "do_run", True):
break
data[i:i + len(piece)] = piece
i = i + len(piece)
else:
return bytes(data)
# Leaving the thread early, without
# reading all of the data this will
# make the connection unusable, refresh it
self._prepare_prefetch_connection(n)
示例8: load_page
# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import CannotSendRequest [as 别名]
def load_page(driver, url, cookies=0):
try:
if cookies == 0:
driver.delete_all_cookies()
time.sleep(1)
if "http" not in url.split("/")[0]:
url = "http://" + url
switch_tab(driver)
driver.get(url)
logging.debug("driver.get(%s) returned successfully" % url)
except (TimeoutException, TimeoutError) as te:
logging.warning("Loading %s timed out" % url)
return str(te)
# try:
# element = WebDriverWait(driver, .5).until(EC.alert_is_present())
# if element is not None:
# print "Alert found on page: " + url
# sys.stdout.flush()
# raise TimeoutError
# else:
# raise NoAlertPresentException
# except (TimeoutException, NoAlertPresentException):
# print "No alert found on page: " + url
# sys.stdout.flush()
# pass
# except TimeoutError as te:
# sys.stdout.flush()
# return str(te)
# try:
# main_handle = driver.current_window_handle
# except CannotSendRequest as csr:
# return str(csr)
try:
windows = driver.window_handles
if len(windows) > 1:
logging.debug("Pop up detected on page: %s. Closing driver instance." % url)
raise TimeoutError
# for window in windows:
# if window != main_handle:
# driver.switch_to_window(window)
# driver.close()
# driver.switch_to_window(main_handle)
# wfrs_status = wait_for_ready_state(driver, 15, 'complete')
# if wfrs_status == "Timed-out":
# print "wait_for_ready_state() timed out."
# raise TimeoutError
except (TimeoutException, TimeoutError) as te:
logging.warning("Loading %s timed out" % url)
return str(te)
return "No Error"