Forums

Connection Error - POST request

I am trying to send data from an outside computer via a POST request. I get the following error client side.

requests.exceptions.ConnectionError: ('Connection aborted.', OSError(0, 'Error'))

#Client side code
import requests
data = {}
url = 'https://www.prestoscore.com'
x = requests.post(url, data)
print(x.text)



#Python anywhere code
@application.route('/', methods=['GET', 'POST'])
def data():
    if request.method == 'POST':
        data = request.json
         print(data)


        return render_template('index.html')

What do you see in your error log? (link to logs are available on the "Web" page on PythonAnywhere).

Nothing appears in the error or server log. That leads me to believe its a client side problem however if I send the request to any other url i get a response instead of an error which leads me to believe its a server issue

More detailed error log:

Traceback (most recent call last):
 File "C:\Users\zacha\AppData\Local\Programs\Python\Python38-32\lib\site-packages\urllib3\connectionpool.py", line 670, in urlopen
httplib_response = self._make_request(
File "C:\Users\zacha\AppData\Local\Programs\Python\Python38-32\lib\site-packages\urllib3\connectionpool.py", line 381, in _make_request    self._validate_conn(conn)
File "C:\Users\zacha\AppData\Local\Programs\Python\Python38-32\lib\site-packages\urllib3\connectionpool.py", line 978, in _validate_conn
conn.connect()
File "C:\Users\zacha\AppData\Local\Programs\Python\Python38-32\lib\site-packages\urllib3\connection.py", line 362, in connect
self.sock = ssl_wrap_socket(
File "C:\Users\zacha\AppData\Local\Programs\Python\Python38-32\lib\site-packages\urllib3\util\ssl_.py", line 384, in ssl_wrap_socket
return context.wrap_socket(sock, server_hostname=server_hostname)
File "C:\Users\zacha\AppData\Local\Programs\Python\Python38-32\lib\ssl.py", line 500, in wrap_socket
return self.sslsocket_class._create(
File "C:\Users\zacha\AppData\Local\Programs\Python\Python38-32\lib\ssl.py", line 1040, in _create
self.do_handshake()
File "C:\Users\zacha\AppData\Local\Programs\Python\Python38-32\lib\ssl.py", line 1309, in do_handshake
self._sslobj.do_handshake()
OSError: [Errno 0] Error

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:\Users\zacha\AppData\Local\Programs\Python\Python38-32\lib\site-packages\requests\adapters.py", 
line 440, in send
resp = conn.urlopen(
File "C:\Users\zacha\AppData\Local\Programs\Python\Python38-32\lib\site-packages\urllib3\connectionpool.py", line 726, in urlopen
retries = retries.increment(
File "C:\Users\zacha\AppData\Local\Programs\Python\Python38-32\lib\site-packages\urllib3\util\retry.py", line 403, in increment
raise six.reraise(type(error), error, _stacktrace)
File "C:\Users\zacha\AppData\Local\Programs\Python\Python38-32\lib\site-packages\urllib3\packages\six.py", line 734, in reraise
raise value.with_traceback(tb)
File "C:\Users\zacha\AppData\Local\Programs\Python\Python38-32\lib\site-packages\urllib3\connectionpool.py", line 670, in urlopen
httplib_response = self._make_request(
File "C:\Users\zacha\AppData\Local\Programs\Python\Python38-32\lib\site-packages\urllib3\connectionpool.py", line 381, in _make_request    self._validate_conn(conn)
File "C:\Users\zacha\AppData\Local\Programs\Python\Python38-32\lib\site-packages\urllib3\connectionpool.py", line 978, in _validate_conn
conn.connect()
File "C:\Users\zacha\AppData\Local\Programs\Python\Python38-32\lib\site-packages\urllib3\connection.py", line 362, in connect
self.sock = ssl_wrap_socket(
File "C:\Users\zacha\AppData\Local\Programs\Python\Python38-32\lib\site-packages\urllib3\util\ssl_.py", line 384, in ssl_wrap_socket
return context.wrap_socket(sock, server_hostname=server_hostname)
File "C:\Users\zacha\AppData\Local\Programs\Python\Python38-32\lib\ssl.py", line 500, in wrap_socket
return self.sslsocket_class._create(
File "C:\Users\zacha\AppData\Local\Programs\Python\Python38-32\lib\ssl.py", line 1040, in _create
self.do_handshake()
File "C:\Users\zacha\AppData\Local\Programs\Python\Python38-32\lib\ssl.py", line 1309, in do_handshake
self._sslobj.do_handshake()
  urllib3.exceptions.ProtocolError: ('Connection aborted.', OSError(0, 'Error'))

  During handling of the above exception, another exception occurred:

 Traceback (most recent call last):
  File [removed for privacy].py", line 20, in <module>
    r = requests.post('https://prestoscore.com/data', files={'[removed for privacy]': f})
  File "C:\Users\zacha\AppData\Local\Programs\Python\Python38-32\lib\site-packages\requests\api.py", line 
   117, in post
      return request('post', url, data=data, json=json, **kwargs)
     File "C:\Users\zacha\AppData\Local\Programs\Python\Python38-32\lib\site-packages\requests\api.py", line 
61, in request
     return session.request(method=method, url=url, **kwargs)
  File "C:\Users\zacha\AppData\Local\Programs\Python\Python38-32\lib\site-packages\requests\sessions.py", 
  line 529, in request
   resp = self.send(prep, **send_kwargs)
   File "C:\Users\zacha\AppData\Local\Programs\Python\Python38-32\lib\site- 
   packages\requests\sessions.py", line 645, in send
   r = adapter.send(request, **kwargs)
   File "C:\Users\zacha\AppData\Local\Programs\Python\Python38-32\lib\site-packages\requests\adapters.py", line 501, in send
    raise ConnectionError(err, request=request)
    requests.exceptions.ConnectionError: ('Connection aborted.', OSError(0, 'Error'))

When I run your code on my local machine I get response 200 and html in x.text

Interesting- I tried again and got a more clear SSL error, tried again just now and got the received text that i have setup so it works properly... .strange

Have you tried to access it form the other machine (from different network location)?