I am making a simple ajax request but for some reason request.is_ajax return false. I am using jquery and Django development server.
$('#save').click(
function()
{
$.ajax({
type: "POST",
url: "/order/start",
});
});
And in views.py
if request.POST and 'save' in request.POST :
if request.is_ajax()== True:
But, it does not return true, and on runserver i see errors
Exception happened during processing of request from ('127.0.0.1', 1625)
Traceback (most recent call last):
File "c:\python27\lib\SocketServer.py", line 284, in _handle_request_noblock
self.process_request(request, client_address)
File "c:\python27\lib\SocketServer.py", line 310, in process_request
self.finish_request(request, client_address)
File "c:\python27\lib\SocketServer.py", line 323, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "c:\python27\lib\site-packages\django\core\servers\basehttp.py", line 56
, in __init__
BaseHTTPRequestHandler.__init__(self, *args, **kwargs)
File "c:\python27\lib\SocketServer.py", line 641, in __init__
self.finish()
File "c:\python27\lib\SocketServer.py", line 694, in finish
self.wfile.flush()
File "c:\python27\lib\socket.py", line 301, in flush
self._sock.sendall(view[write_offset:write_offset+buffer_size])
error: [Errno 10053] An established connection was aborted by the software in y
ur host machine
I guess that you have the standard middleware enabled and settings.APPEND_SLASH is True (the default), which means that POSTing to "/order/start" automatically redirects to "/order/start/" with a slash, losing the POST in the process.
Make sure the URL in your JS ends with a slash.
Related
i'm using django as a backend server and flutter as a mobile app.
when i request a 3d model from my django app the message
Exception occurred during processing of request from ('127.0.0.1', 49163)
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/socketserver.py", line 683, in process_request_thread
self.finish_request(request, client_address)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/socketserver.py", line 360, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/socketserver.py", line 747, in __init__
self.handle()
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/django/core/servers/basehttp.py", line 174, in handle
self.handle_one_request()
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/django/core/servers/basehttp.py", line 182, in handle_one_request
self.raw_requestline = self.rfile.readline(65537)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/socket.py", line 704, in readinto
return self._sock.recv_into(b)
ConnectionResetError: [Errno 54] Connection reset by peer
but when i open the same file from another online server it works! what should i do?
I am trying to deploy a helloWorld.sol using brownie. I am getting below error when I tried to run brownie run scripts/deploy.py.
Terminating local RPC client... Exception in thread Thread-5:
Traceback (most recent call last): File
"C:\Users\mmasn.local\pipx\venvs\eth-brownie\lib\site-packages\urllib3\connection.py",
line 175, in _new_conn
(self._dns_host, self.port), self.timeout, **extra_kw File "C:\Users\mmasn.local\pipx\venvs\eth-brownie\lib\site-packages\urllib3\util\connection.py",
line 96, in create_connection
raise err File "C:\Users\mmasn.local\pipx\venvs\eth-brownie\lib\site-packages\urllib3\util\connection.py",
line 86, in create_connection
sock.connect(sa) ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused
it
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File
"C:\Users\mmasn.local\pipx\venvs\eth-brownie\lib\site-packages\urllib3\connectionpool.py",
line 706, in urlopen
chunked=chunked, File "C:\Users\mmasn.local\pipx\venvs\eth-brownie\lib\site-packages\urllib3\connectionpool.py",
line 394, in _make_request
conn.request(method, url, **httplib_request_kw) File "C:\Users\mmasn.local\pipx\venvs\eth-brownie\lib\site-packages\urllib3\connection.py",
line 239, in request
super(HTTPConnection, self).request(method, url, body=body, headers=headers) File "C:\Program
Files\Python37\lib\http\client.py", line 1229, in request
self._send_request(method, url, body, headers, encode_chunked) File "C:\Program Files\Python37\lib\http\client.py", line 1275, in
_send_request
self.endheaders(body, encode_chunked=encode_chunked) File "C:\Program Files\Python37\lib\http\client.py", line 1224, in
endheaders
self._send_output(message_body, encode_chunked=encode_chunked) File "C:\Program Files\Python37\lib\http\client.py", line 1016, in
_send_output
self.send(msg) File "C:\Program Files\Python37\lib\http\client.py", line 956, in send
self.connect() File "C:\Users\mmasn.local\pipx\venvs\eth-brownie\lib\site-packages\urllib3\connection.py",
line 205, in connect
conn = self._new_conn() File "C:\Users\mmasn.local\pipx\venvs\eth-brownie\lib\site-packages\urllib3\connection.py",
line 187, in _new_conn
self, "Failed to establish a new connection: %s" % e urllib3.exceptions.NewConnectionError:
<urllib3.connection.HTTPConnection object at 0x0000021DAA2A0F28>:
Failed to establish a new connection: [WinError 10061] No connection
could be made because the target machine actively refused it
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File
"C:\Users\mmasn.local\pipx\venvs\eth-brownie\lib\site-packages\requests\adapters.py",
line 449, in send
timeout=timeout File "C:\Users\mmasn.local\pipx\venvs\eth-brownie\lib\site-packages\urllib3\connectionpool.py",
line 756, in urlopen
method, url, error=e, _pool=self, _stacktrace=sys.exc_info()[2] File
"C:\Users\mmasn.local\pipx\venvs\eth-brownie\lib\site-packages\urllib3\util\retry.py",
line 574, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause)) urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='127.0.0.1',
port=8545): Max retries exceeded with url: / (Caused by
NewConnectionError('<urllib3.connection.HTTPConnection object at
0x0000021DAA2A0F28>: Failed to establish a new connection: [WinError
10061] No connection could be made because the target machine actively
refused it'))
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File
"C:\Users\mmasn.local\pipx\venvs\eth-brownie\lib\site-packages\brownie\network\rpc\ganache.py",
line 82, in _request
response = web3.provider.make_request(method, args) # type: ignore File
"C:\Users\mmasn.local\pipx\venvs\eth-brownie\lib\site-packages\web3\providers\rpc.py",
line 91, in make_request
**self.get_request_kwargs() File "C:\Users\mmasn.local\pipx\venvs\eth-brownie\lib\site-packages\web3_utils\request.py",
line 48, in make_post_request
response = session.post(endpoint_uri, data=data, *args, **kwargs) # type: ignore File "C:\Users\mmasn.local\pipx\venvs\eth-brownie\lib\site-packages\requests\sessions.py",
line 590, in post
return self.request('POST', url, data=data, json=json, **kwargs) File
"C:\Users\mmasn.local\pipx\venvs\eth-brownie\lib\site-packages\requests\sessions.py",
line 542, in request
resp = self.send(prep, **send_kwargs) File "C:\Users\mmasn.local\pipx\venvs\eth-brownie\lib\site-packages\requests\sessions.py",
line 655, in send
r = adapter.send(request, **kwargs) File "C:\Users\mmasn.local\pipx\venvs\eth-brownie\lib\site-packages\requests\adapters.py",
line 516, in send
raise ConnectionError(e, request=request) requests.exceptions.ConnectionError:
HTTPConnectionPool(host='127.0.0.1', port=8545): Max retries exceeded
with url: / (Caused by
NewConnectionError('<urllib3.connection.HTTPConnection object at
0x0000021DAA2A0F28>: Failed to establish a new connection: [WinError
10061] No connection could be made because the target machine
actively refused it'))
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File "C:\Program
Files\Python37\lib\threading.py", line 917, in _bootstrap_inner
self.run() File "C:\Program Files\Python37\lib\threading.py", line 865, in run
self._target(*self._args, **self._kwargs) File "C:\Users\mmasn.local\pipx\venvs\eth-brownie\lib\site-packages\brownie\network\state.py",
line 332, in add_to_undo_buffer
self.sleep(0) File "C:\Users\mmasn.local\pipx\venvs\eth-brownie\lib\site-packages\brownie\network\state.py",
line 375, in sleep
self.time_offset = int(rpc.Rpc().sleep(seconds)) File "C:\Users\mmasn.local\pipx\venvs\eth-brownie\lib\site-packages\brownie\network\rpc_init.py",
line 45, in wrapped
return fn(*args, **kwargs) File "C:\Users\mmasn.local\pipx\venvs\eth-brownie\lib\site-packages\brownie\network\rpc_init.py",
line 166, in sleep
return self.backend.sleep(seconds) File "C:\Users\mmasn.local\pipx\venvs\eth-brownie\lib\site-packages\brownie\network\rpc\ganache.py",
line 91, in sleep
return _request("evm_increaseTime", [seconds]) File "C:\Users\mmasn.local\pipx\venvs\eth-brownie\lib\site-packages\brownie\network\rpc\ganache.py",
line 86, in _request
raise RPCRequestError("Web3 is not connected.") brownie.exceptions.RPCRequestError: Web3 is not connected.
My deploy.py code is below.
from brownie import accounts, HelloWorld
def deployHelloWorld():
account = accounts[0]
helloWorldObject = HelloWorld.deploy({"from": account})
helloWorldObject.setName("Michael", {"from": account})
greeting = helloWorldObject.sayHello()
print(greeting)
def main():
deployHelloWorld()
could you please help?
This error is caused because there is no waiting after transaction. By using transaction.wait(1), as below, the problem is fixed.
transaction = helloWorldObject.setName("Michael", {"from": account})
transaction.wait(1)
greeting = helloWorldObject.sayHello()
print(greeting)
RPC is sometimes killed too quick, resulting in brownie.exceptions.RPCRequestError: Web3 is not connected.
Therefore you have to add the time.sleep(1) after every transaction to ensure your code runs smoothly.
You need to put after transactions
transactionVariable.wait(1)
time.sleep(1)
I am using https://github.com/teddziuba/django-sslserver as an https server for my django-rest app. it works fine if I test it on admin or in chrome's api client(when admin runs on chrome as well). But whenever I try to test it from firefox, I get the following exception:
Exception happened during processing of request from ('127.0.0.1', 51984)
Traceback (most recent call last):
File "/usr/lib/python2.7/SocketServer.py", line 295, in _handle_request_noblock
self.process_request(request, client_address)
File "/usr/lib/python2.7/SocketServer.py", line 321, in process_request
self.finish_request(request, client_address)
File "/usr/lib/python2.7/SocketServer.py", line 334, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "/home/diwakar/virtualenvs/everybillapienv/local/lib/python2.7/site-packages/django/core/servers/basehttp.py", line 102, in __init__
super(WSGIRequestHandler, self).__init__(*args, **kwargs)
File "/usr/lib/python2.7/SocketServer.py", line 649, in __init__
self.handle()
File "/home/diwakar/virtualenvs/everybillapienv/local/lib/python2.7/site-packages/django/core/servers/basehttp.py", line 167, in handle
self.raw_requestline = self.rfile.readline(65537)
File "/usr/lib/python2.7/socket.py", line 476, in readline
data = self._sock.recv(self._rbufsize)
File "/usr/lib/python2.7/ssl.py", line 341, in recv
return self.read(buflen)
File "/usr/lib/python2.7/ssl.py", line 260, in read
return self._sslobj.read(len)
SSLError: [Errno 1] _ssl.c:1429: error:14094418:SSL routines:SSL3_READ_BYTES:tlsv1 alert unknown ca
Should I use that csrf_exempt decorator to get rid of this exception ? my app only have a mobile client, it would never have an browser/javascript client for sure.
How strong is django-sslserver ? Can I use it on production ?
What should be the easiest way to redirect http traffic to https here, I've heard a combination of easy-userena and django-privatebeta does it. Any suggestions ?
I'm getting this error below after set SESSION_EXPIRE_AT_BROWSER_CLOSE = True on my settings.py. I can open and login and logout with no errors...but if I close before login I get this error. Is there a way to fix it?
Thanks in advance!
----------------------------------------
Exception happened during processing of request from ('127.0.0.1', 63792)
Traceback (most recent call last):
File "c:\Python27\lib\SocketServer.py", line 582, in process_request_thread
self.finish_request(request, client_address)
File "c:\Python27\lib\SocketServer.py", line 323, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "c:\Python27\lib\site-packages\django\core\servers\basehttp.py", line 150
, in __init__
super(WSGIRequestHandler, self).__init__(*args, **kwargs)
File "c:\Python27\lib\SocketServer.py", line 638, in __init__
self.handle()
File "c:\Python27\lib\wsgiref\simple_server.py", line 116, in handle
self.raw_requestline = self.rfile.readline()
File "c:\Python27\lib\socket.py", line 447, in readline
data = self._sock.recv(self._rbufsize)
error: [Errno 10054] An existing connection was cancelled by the remote host
----------------------------------------
I'm running some basic functional web test with the Selenium web driver and I'm noticing this error in two of my functional web test cases. The test cases all pass at the end but I get this in the console:
Exception happened during processing of request from ('127.0.0.1', 1169)
data = self._sock.recv(self._rbufsize)
error: [Errno 10054] An existing connection was forcibly closed by the remote host
Traceback (most recent call last):
File "C:\dev\django-projects\barbwire\venv\lib\site-packages\django\test\testcases.py", line 981, in _handle_request_noblock
self.process_request(request, client_address)
File "C:\Python27\Lib\SocketServer.py", line 310, in process_request
self.finish_request(request, client_address)
File "C:\Python27\Lib\SocketServer.py", line 323, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "C:\dev\django-projects\barbwire\venv\lib\site-packages\django\core\servers\basehttp.py", line 139, in __init__
super(WSGIRequestHandler, self).__init__(*args, **kwargs)
File "C:\Python27\Lib\SocketServer.py", line 638, in __init__
self.handle()
File "C:\Python27\Lib\wsgiref\simple_server.py", line 116, in handle
self.raw_requestline = self.rfile.readline()
File "C:\Python27\Lib\socket.py", line 447, in readline
data = self._sock.recv(self._rbufsize)
error: [Errno 10054] An existing connection was forcibly closed by the remote host
Traceback (most recent call last):
File "C:\dev\django-projects\barbwire\venv\lib\site-packages\django\test\testcases.py", line 981, in _handle_request_noblock
self.process_request(request, client_address)
File "C:\Python27\Lib\SocketServer.py", line 310, in process_request
self.finish_request(request, client_address)
File "C:\Python27\Lib\SocketServer.py", line 323, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "C:\dev\django-projects\barbwire\venv\lib\site-packages\django\core\servers\basehttp.py", line 139, in __init__
super(WSGIRequestHandler, self).__init__(*args, **kwargs)
File "C:\Python27\Lib\SocketServer.py", line 638, in __init__
self.handle()
File "C:\Python27\Lib\wsgiref\simple_server.py", line 116, in handle
self.raw_requestline = self.rfile.readline()
File "C:\Python27\Lib\socket.py", line 447, in readline
data = self._sock.recv(self._rbufsize)
error: [Errno 10054] An existing connection was forcibly closed by the remote host
----------------------------------------
----------------------------------------
Exception happened during processing of request from ('127.0.0.1', 1170)
----------------------------------------
Destroying test database for alias 'default'...
Here's an example of one of the test cases:
def test_can_join_main_site(self):
self.browser.get(self.live_server_url)
self.browser.find_element_by_link_text('Register').click()
time.sleep(5)
self.browser.find_element_by_name('submit').click()
time.sleep(5)
It runs to completion but dumps the above exception. The idea is to test a simple registration page. After clicking the submit button the page re-displays and prompts the user to fill out additional form fields. As expected and everything appears to work correctly but why the errors? Am I missing something?
Replacing localhost with 127.0.0.1 did not work for me, and adding sleep just slows the test down. I was able to get rid of the error by calling refresh before quitting the browser:
from selenium import webdriver
browser = webdriver.Firefox()
# do stuff with browser
browser.refresh()
browser.quit()
In my case it was the loading of static files in <link> and <script> tags that was causing the problem. But it went away when I added refresh before quitting.
Using FireFox, I was able to resolve this by sufficiently slowing the shutdown process:
#classmethod
def tearDownClass(cls):
time.sleep(3)
cls.selenium.quit()
time.sleep(3)
super(TestClass, cls).tearDownClass()
I fixed the problem by replacing localhost with 127.0.0.1 in the URL:
url = self.live_server_url
url = url.replace('localhost', '127.0.0.1')
self.driver.get('%s%s' % (url, reverse('whatever')))
I found the solution here: https://code.djangoproject.com/ticket/15178
Django Debug Toolbar generates tons of these errors. uninstall it and try again