本文整理汇总了Python中socks.ProxyError方法的典型用法代码示例。如果您正苦于以下问题:Python socks.ProxyError方法的具体用法?Python socks.ProxyError怎么用?Python socks.ProxyError使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类socks
的用法示例。
在下文中一共展示了socks.ProxyError方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: getwork
# 需要导入模块: import socks [as 别名]
# 或者: from socks import ProxyError [as 别名]
def getwork(self, data=None):
try:
self.connection = self.ensure_connected(self.connection, self.server().proto, self.server().host)[0]
self.postdata['params'] = if_else(data, [data], [])
(self.connection, result) = self.request(self.connection, '/', self.headers, dumps(self.postdata))
self.switch.connection_ok()
return result['result']
except (IOError, httplib.HTTPException, ValueError, socks.ProxyError, NotAuthorized, RPCError):
self.stop()
except Exception:
say_exception()
示例2: long_poll_thread
# 需要导入模块: import socks [as 别名]
# 或者: from socks import ProxyError [as 别名]
def long_poll_thread(self):
last_host = None
while True:
if self.should_stop or self.authorization_failed:
return
url = self.long_poll_url
if url != '':
proto = self.server().proto
host = self.server().host
parsedUrl = urlsplit(url)
if parsedUrl.scheme != '':
proto = parsedUrl.scheme
if parsedUrl.netloc != '':
host = parsedUrl.netloc
url = url[url.find(host) + len(host):]
if url == '': url = '/'
try:
if host != last_host: self.close_lp_connection()
self.lp_connection, changed = self.ensure_connected(self.lp_connection, proto, host)
if changed:
say_line("LP connected to %s", self.server().name)
last_host = host
self.long_poll_active = True
response = self.request(self.lp_connection, url, self.headers, timeout=self.long_poll_timeout)
self.long_poll_active = False
if response:
(self.lp_connection, result) = response
self.queue_work(result['result'])
if self.options.verbose:
say_line('long poll: new block %s%s', (result['result']['data'][56:64], result['result']['data'][48:56]))
except (IOError, httplib.HTTPException, ValueError, socks.ProxyError, NotAuthorized, RPCError):
say_exception('long poll IO error')
self.close_lp_connection()
sleep(.5)
except Exception:
say_exception()
示例3: _new_conn
# 需要导入模块: import socks [as 别名]
# 或者: from socks import ProxyError [as 别名]
def _new_conn(self):
"""
Establish a new connection via the SOCKS proxy.
"""
extra_kw = {}
if self.source_address:
extra_kw['source_address'] = self.source_address
if self.socket_options:
extra_kw['socket_options'] = self.socket_options
try:
conn = socks.create_connection(
(self.host, self.port),
proxy_type=self._socks_options['socks_version'],
proxy_addr=self._socks_options['proxy_host'],
proxy_port=self._socks_options['proxy_port'],
proxy_username=self._socks_options['username'],
proxy_password=self._socks_options['password'],
timeout=self.timeout,
**extra_kw
)
except SocketTimeout as e:
raise ConnectTimeoutError(
self, "Connection to %s timed out. (connect timeout=%s)" %
(self.host, self.timeout))
except socks.ProxyError as e:
# This is fragile as hell, but it seems to be the only way to raise
# useful errors here.
if e.socket_err:
error = e.socket_err
if isinstance(error, SocketTimeout):
raise ConnectTimeoutError(
self,
"Connection to %s timed out. (connect timeout=%s)" %
(self.host, self.timeout)
)
else:
raise NewConnectionError(
self,
"Failed to establish a new connection: %s" % error
)
else:
raise NewConnectionError(
self,
"Failed to establish a new connection: %s" % e
)
except SocketError as e: # Defensive: PySocks should catch all these.
raise NewConnectionError(
self, "Failed to establish a new connection: %s" % e)
return conn
# We don't need to duplicate the Verified/Unverified distinction from
# urllib3/connection.py here because the HTTPSConnection will already have been
# correctly set to either the Verified or Unverified form by that module. This
# means the SOCKSHTTPSConnection will automatically be the correct type.
示例4: send
# 需要导入模块: import socks [as 别名]
# 或者: from socks import ProxyError [as 别名]
def send(self, payload):
response = b''
code = 200
error = ''
human_error = ''
try:
response = self.channel_loaded.send(
payload,
self._additional_handlers()
)
except socks.ProxyError as e:
if e.socket_err and e.socket_err.errno:
code = e.socket_err.errno
if e.msg:
error = str(e.msg)
human_error = messages.module_shell_php.error_proxy
except HTTPError as e:
if e.code:
code = e.code
if e.reason:
error = str(e.reason)
if code == 404:
human_error = messages.module_shell_php.error_404_remote_backdoor
elif code == 500:
human_error = messages.module_shell_php.error_500_executing
elif code != 200:
human_error = messages.module_shell_php.error_i_executing % code
except URLError as e:
code = 0
if e.reason:
error = str(e.reason)
human_error = messages.module_shell_php.error_URLError_network
if response:
dlog.info('RESPONSE: %s' % repr(response))
else:
response = b''
command_last_chars = utils.prettify.shorten(
payload.rstrip(),
keep_trailer = 10
)
if (
command_last_chars and
command_last_chars[-1] not in ( ';', '}' )
):
log.warning(messages.module_shell_php.missing_php_trailer_s % command_last_chars)
if error or human_error:
log.debug('[ERR] %s [%s]' % (error, code))
log.warning(human_error)
return response, code, error