I had a create a REST API using bottle framework, which receives calls from GAE. Once this REST API is invoked, it did some calculations and sent outputs as a zip file to AMAZON S3 server and return the link to GAE. Everything works fine expect the timeout issue. I tried to adjust the deadline of urlfetch to 60 seconds, which did not solve the problem. I appreciate any suggestions.
GAE side:
response = urlfetch.fetch(url=url, payload=data, method=urlfetch.POST, headers=http_headers, deadline=60)
Broser error info.:
Traceback (most recent call last):
File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.5.2\webapp2.py", line 1535, in __call__
rv = self.handle_exception(request, response, e)
File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.5.2\webapp2.py", line 1529, in __call__
rv = self.router.dispatch(request, response)
File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.5.2\webapp2.py", line 1278, in default_dispatcher
return route.handler_adapter(request, response)
File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.5.2\webapp2.py", line 1102, in __call__
return handler.dispatch()
File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.5.2\webapp2.py", line 572, in dispatch
return self.handle_exception(e, self.app.debug)
File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.5.2\webapp2.py", line 570, in dispatch
return method(*args, **kwargs)
File "D:\Dropbox\ubertool_src\przm5/przm5_output.py", line 22, in post
przm5_obj = przm5_rest_model.przm5(args)
File "D:\Dropbox\ubertool_src\przm5\przm5_rest_model.py", line 351, in __init__
self.convertSoil1, self.convert1to3, self.convert2to3)
File "D:\Dropbox\ubertool_src\przm5\przm5_rest_model.py", line 135, in get_jid
response = urlfetch.fetch(url=url, payload=data, method=urlfetch.POST, headers=http_headers)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\api\urlfetch.py", line 270, in fetch
return rpc.get_result()
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\api\apiproxy_stub_map.py", line 612, in get_result
return self.__get_result_hook(self)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\api\urlfetch.py", line 410, in _get_fetch_result
'Deadline exceeded while waiting for HTTP response from URL: ' + url)
DeadlineExceededError: Deadline exceeded while waiting for HTTP response from URL: http://localhost:7777/my_model
REST server:
#route('/my_model', method='POST')
#auth_basic(check)
def my_model():
#run the model
run_my model()
#zip output files
zout=zipfile.ZipFile("test.zip","w")
for name in os.listdir(src1):
zout.write(name)
zout.close()
##upload file to S3
conn = S3Connection(key, secretkey)
bucket = Bucket(conn, 'przm5')
k=Key(bucket)
name1='PRZM5_'+name_temp+'.zip'
k.key=name1
###All the above steps are fine####
k.set_contents_from_filename('test.zip')
link='https://s3.amazonaws.com/'+my_file_path
return {'ff': ff}
run(host='localhost', port=7777, debug=True)
Errors from the REST server:
127.0.0.1 - - [07/Jan/2014 16:16:36] "POST /my_model HTTP/1.1" 200 1663
Traceback (most recent call last):
File "C:\Python27\Lib\wsgiref\handlers.py", line 86, in run
self.finish_response()
File "C:\Python27\Lib\wsgiref\handlers.py", line 128, in finish_response
self.write(data)
File "C:\Python27\Lib\wsgiref\handlers.py", line 212, in write
self.send_headers()
File "C:\Python27\Lib\wsgiref\handlers.py", line 270, in send_headers
self.send_preamble()
File "C:\Python27\Lib\wsgiref\handlers.py", line 194, in send_preamble
'Date: %s\r\n' % format_date_time(time.time())
File "C:\Python27\Lib\socket.py", line 324, in write
self.flush()
File "C:\Python27\Lib\socket.py", line 303, in flush
self._sock.sendall(view[write_offset:write_offset+buffer_size])
error: [Errno 10053] An established connection was aborted by the software in your host machine
127.0.0.1 - - [07/Jan/2014 16:16:36] "POST /my_model HTTP/1.1" 500 59
----------------------------------------
Exception happened during processing of request from ('127.0.0.1', 50953)
Traceback (most recent call last):
File "C:\Python27\Lib\SocketServer.py", line 295, in _handle_request_noblock
self.process_request(request, client_address)
File "C:\Python27\Lib\SocketServer.py", line 321, in process_request
self.finish_request(request, client_address)
File "C:\Python27\Lib\SocketServer.py", line 334, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "C:\Python27\Lib\SocketServer.py", line 651, in __init__
self.finish()
File "C:\Python27\Lib\SocketServer.py", line 710, in finish
self.wfile.close()
File "C:\Python27\Lib\socket.py", line 279, in close
self.flush()
File "C:\Python27\Lib\socket.py", line 303, in flush
self._sock.sendall(view[write_offset:write_offset+buffer_size])
error: [Errno 10053] An established connection was aborted by the software in your host machine
The deadline is a maximum value, once reached it'll fail. And it's failing with
Deadline exceeded while waiting for HTTP response
So you should try to catch that exception and try again.
If the entire operation can't be done in under 60 seconds then there is nothing else to be done, it's a hard limit in GAE that HTTP requests can't exceed 60 seconds.
Related
I am trying to troubleshoot a situation.
I am initiating a Boto3 client like this:
s3_client = boto3.client('s3')
Then I am iterating over a number of files and uploading them using:
s3_client.upload_file()
My problem is that every now and then I see it pausing for 60 seconds and then continuing normally.
I've tried reducing the timeout value and the error I seem to be getting is:
botocore.exceptions.ConnectTimeoutError
or
urllib3.exceptions.ConnectTimeoutError
If I leave it at 60, eventually it succeeds and I don't get any errors.
My question is, this error means that when executing upload_file, it tried to send a put request to the server and the server didn't respond to that request?
When initiating the client, is any connection established that could be lost or that's simply only storing the credentials and it's irrelevant to this issue?
Many thanks.
Update: Adding more detailed logs:
CRITICAL Connect timeout
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/urllib3/connection.py", line 169, in _new_conn
conn = connection.create_connection(
File "/usr/lib/python3/dist-packages/urllib3/util/connection.py", line 96, in create_connection
raise err
File "/usr/lib/python3/dist-packages/urllib3/util/connection.py", line 86, in create_connection
sock.connect(sa)
TimeoutError: timed out
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/user/.local/lib/python3.10/site-packages/botocore/httpsession.py", line 439, in send
urllib_response = conn.urlopen(
File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 755, in urlopen
retries = retries.increment(
File "/usr/lib/python3/dist-packages/urllib3/util/retry.py", line 507, in increment
raise six.reraise(type(error), error, _stacktrace)
File "/usr/lib/python3/dist-packages/six.py", line 719, in reraise
raise value
File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 699, in urlopen
httplib_response = self._make_request(
File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 382, in _make_request
self._validate_conn(conn)
File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 1012, in _validate_conn
conn.connect()
File "/usr/lib/python3/dist-packages/urllib3/connection.py", line 353, in connect
conn = self._new_conn()
File "/usr/lib/python3/dist-packages/urllib3/connection.py", line 174, in _new_conn
raise ConnectTimeoutError(
urllib3.exceptions.ConnectTimeoutError
During handling of the above exception, another exception occurred:
File "/home/user/.local/lib/python3.10/site-packages/boto3/s3/inject.py", line 143, in upload_file
return transfer.upload_file(
File "/home/user/.local/lib/python3.10/site-packages/boto3/s3/transfer.py", line 288, in upload_file
future.result()
File "/home/user/.local/lib/python3.10/site-packages/s3transfer/futures.py", line 103, in result
return self._coordinator.result()
File "/home/user/.local/lib/python3.10/site-packages/s3transfer/futures.py", line 266, in result
raise self._exception
File "/home/user/.local/lib/python3.10/site-packages/s3transfer/tasks.py", line 139, in __call__
return self._execute_main(kwargs)
File "/home/user/.local/lib/python3.10/site-packages/s3transfer/tasks.py", line 162, in _execute_main
return_value = self._main(**kwargs)
File "/home/user/.local/lib/python3.10/site-packages/s3transfer/upload.py", line 758, in _main
client.put_object(Bucket=bucket, Key=key, Body=body, **extra_args)
File "/home/user/.local/lib/python3.10/site-packages/botocore/client.py", line 415, in _api_call
return self._make_api_call(operation_name, kwargs)
File "/home/user/.local/lib/python3.10/site-packages/botocore/client.py", line 731, in _make_api_call
http, parsed_response = self._make_request(
File "/home/user/.local/lib/python3.10/site-packages/botocore/client.py", line 751, in _make_request
return self._endpoint.make_request(operation_model, request_dict)
File "/home/user/.local/lib/python3.10/site-packages/botocore/endpoint.py", line 107, in make_request
return self._send_request(request_dict, operation_model)
File "/home/user/.local/lib/python3.10/site-packages/botocore/endpoint.py", line 183, in _send_request
while self._needs_retry(attempts, operation_model, request_dict,
File "/home/user/.local/lib/python3.10/site-packages/botocore/endpoint.py", line 305, in _needs_retry
responses = self._event_emitter.emit(
File "/home/user/.local/lib/python3.10/site-packages/botocore/hooks.py", line 358, in emit
return self._emitter.emit(aliased_event_name, **kwargs)
File "/home/user/.local/lib/python3.10/site-packages/botocore/hooks.py", line 229, in emit
return self._emit(event_name, kwargs)
File "/home/user/.local/lib/python3.10/site-packages/botocore/hooks.py", line 212, in _emit
response = handler(**kwargs)
File "/home/user/.local/lib/python3.10/site-packages/botocore/retryhandler.py", line 194, in __call__
if self._checker(**checker_kwargs):
File "/home/user/.local/lib/python3.10/site-packages/botocore/retryhandler.py", line 267, in __call__
should_retry = self._should_retry(attempt_number, response,
File "/home/user/.local/lib/python3.10/site-packages/botocore/retryhandler.py", line 294, in _should_retry
return self._checker(attempt_number, response, caught_exception)
File "/home/user/.local/lib/python3.10/site-packages/botocore/retryhandler.py", line 333, in __call__
checker_response = checker(attempt_number, response,
File "/home/user/.local/lib/python3.10/site-packages/botocore/retryhandler.py", line 233, in __call__
return self._check_caught_exception(
File "/home/user/.local/lib/python3.10/site-packages/botocore/retryhandler.py", line 376, in _check_caught_exception
raise caught_exception
File "/home/user/.local/lib/python3.10/site-packages/botocore/endpoint.py", line 249, in _do_get_response
http_response = self._send(request)
File "/home/user/.local/lib/python3.10/site-packages/botocore/endpoint.py", line 321, in _send
return self.http_session.send(request)
File "/home/user/.local/lib/python3.10/site-packages/botocore/httpsession.py", line 472, in send
raise ConnectTimeoutError(endpoint_url=request.url, error=e)
The default boto3 retry mode (Legacy) doesn't properly handle a number of errors/exceptions, including RequestThrottled, PriorRequestNotComplete, ConnectionError and BandwidthLimitExceeded. It can manifest as very intermittent problems with long delays and repeated connection failures. You'll likely be better off using the Standard retry mode instead, which also has an exponential backoff.
import boto3
from botocore.client import Config as BotoConfig
TIMEOUT = 3
config = BotoConfig(connect_timeout=TIMEOUT, retries={"mode": "standard"})
client = boto3.client("s3", config=config)
I'm running trading bots written in python in VS Code on mac, trading at binance exchange.
Unfortunately I get sporadic errors when the bot is placing orders, respectively connect via websocket. I really can't explain what's going on because the bots are running well for one or two days and then suddenly this error is disrupting the strategy, because it causes that orders are not cancelled anymore when they should leading to unsecured trades (without stop).
Message: 'Starting new HTTPS connection (%d): %s:%s'
Arguments: (1, 'fapi.binance.com', 443)
--- Logging error ---
Traceback (most recent call last):
File "/Users/username/anaconda3/lib/python3.7/logging/__init__.py", line 1038, in emit
self.flush()
File "/Users/username/anaconda3/lib/python3.7/logging/__init__.py", line 1018, in flush
self.stream.flush()
PermissionError: [Errno 13] Permission denied
Call stack:
File "/Users/username/anaconda3/lib/python3.7/threading.py", line 885, in _bootstrap
self._bootstrap_inner()
File "/Users/username/anaconda3/lib/python3.7/threading.py", line 917, in _bootstrap_inner
self.run()
File "/Users/username/anaconda3/lib/python3.7/threading.py", line 865, in run
self._target(*self._args, **self._kwargs)
File "/Users/username/Workfiles/python/binance/vs_binance_algo/ETH_LinReg/engine_LinReg.py", line 102, in execute
execution_short_ETH.main()
File "/Users/username/Workfiles/python/binance/vs_binance_algo/ETH_LinReg/execution_short_ETH.py", line 22, in main
response_tradelist = sr.send_signed_request('GET', '/fapi/v1/userTrades', params)
File "/Users/username/Workfiles/python/binance/vs_binance_algo/ETH_LinReg/send_requests_ETH.py", line 49, in send_signed_request
response = dispatch_request(http_method)(**params)
File "/Users/username/anaconda3/lib/python3.7/site-packages/requests/sessions.py", line 546, in get
return self.request('GET', url, **kwargs)
File "/Users/username/anaconda3/lib/python3.7/site-packages/requests/sessions.py", line 533, in request
resp = self.send(prep, **send_kwargs)
File "/Users/username/anaconda3/lib/python3.7/site-packages/requests/sessions.py", line 646, in send
r = adapter.send(request, **kwargs)
File "/Users/username/anaconda3/lib/python3.7/site-packages/requests/adapters.py", line 449, in send
timeout=timeout
File "/Users/username/anaconda3/lib/python3.7/site-packages/urllib3/connectionpool.py", line 600, in urlopen
chunked=chunked)
File "/Users/username/anaconda3/lib/python3.7/site-packages/urllib3/connectionpool.py", line 393, in _make_request
httplib_response.length)
Message: '%s://%s:%s "%s %s %s" %s %s'
Arguments: ('https', 'fapi.binance.com', 443, 'GET', '/fapi/v1/userTrades?timestamp=1630094893528&signature=456f8b3cf34a36ad257114d4e8a7ca31d43c27ddb8ad8296bc7e3d3d416f9145', 'HTTP/1.1', 200, None)
--- Logging error ---
Traceback (most recent call last):
File "/Users/username/anaconda3/lib/python3.7/logging/__init__.py", line 1038, in emit
self.flush()
File "/Users/username/anaconda3/lib/python3.7/logging/__init__.py", line 1018, in flush
self.stream.flush()
PermissionError: [Errno 13] Permission denied
Call stack:
File "/Users/username/anaconda3/lib/python3.7/threading.py", line 885, in _bootstrap
self._bootstrap_inner()
File "/Users/username/anaconda3/lib/python3.7/threading.py", line 917, in _bootstrap_inner
self.run()
File "/Users/username/anaconda3/lib/python3.7/threading.py", line 865, in run
self._target(*self._args, **self._kwargs)
File "/Users/username/Workfiles/python/binance/vs_binance_algo/ETH_LinReg/engine_LinReg.py", line 102, in execute
execution_short_ETH.main()
File "/Users/username/Workfiles/python/binance/vs_binance_algo/ETH_LinReg/execution_short_ETH.py", line 34, in main
#response = sr.send_public_request('/fapi/v1/ticker/24hr?symbol='+symbol)
File "/Users/username/Workfiles/python/binance/vs_binance_algo/ETH_LinReg/send_requests_ETH.py", line 59, in send_public_request
response = dispatch_request('GET')(url=url)
File "/Users/username/anaconda3/lib/python3.7/site-packages/requests/sessions.py", line 546, in get
return self.request('GET', url, **kwargs)
File "/Users/username/anaconda3/lib/python3.7/site-packages/requests/sessions.py", line 533, in request
resp = self.send(prep, **send_kwargs)
File "/Users/username/anaconda3/lib/python3.7/site-packages/requests/sessions.py", line 646, in send
r = adapter.send(request, **kwargs)
File "/Users/username/anaconda3/lib/python3.7/site-packages/requests/adapters.py", line 449, in send
timeout=timeout
File "/Users/username/anaconda3/lib/python3.7/site-packages/urllib3/connectionpool.py", line 588, in urlopen
conn = self._get_conn(timeout=pool_timeout)
File "/Users/username/anaconda3/lib/python3.7/site-packages/urllib3/connectionpool.py", line 248, in _get_conn
return conn or self._new_conn()
File "/Users/username/anaconda3/lib/python3.7/site-packages/urllib3/connectionpool.py", line 813, in _new_conn
self.num_connections, self.host, self.port or "443")
Message: 'Starting new HTTPS connection (%d): %s:%s'
Arguments: (1, 'fapi.binance.com', 443)
--- Logging error ---
Traceback (most recent call last):
File "/Users/username/anaconda3/lib/python3.7/logging/__init__.py", line 1038, in emit
self.flush()
File "/Users/username/anaconda3/lib/python3.7/logging/__init__.py", line 1018, in flush
self.stream.flush()
PermissionError: [Errno 13] Permission denied
Call stack:
File "/Users/username/anaconda3/lib/python3.7/threading.py", line 885, in _bootstrap
self._bootstrap_inner()
File "/Users/username/anaconda3/lib/python3.7/threading.py", line 917, in _bootstrap_inner
self.run()
File "/Users/username/anaconda3/lib/python3.7/threading.py", line 865, in run
self._target(*self._args, **self._kwargs)
File "/Users/username/Workfiles/python/binance/vs_binance_algo/ETH_LinReg/engine_LinReg.py", line 102, in execute
execution_short_ETH.main()
File "/Users/username/Workfiles/python/binance/vs_binance_algo/ETH_LinReg/execution_short_ETH.py", line 34, in main
#response = sr.send_public_request('/fapi/v1/ticker/24hr?symbol='+symbol)
File "/Users/username/Workfiles/python/binance/vs_binance_algo/ETH_LinReg/send_requests_ETH.py", line 59, in send_public_request
response = dispatch_request('GET')(url=url)
File "/Users/username/anaconda3/lib/python3.7/site-packages/requests/sessions.py", line 546, in get
return self.request('GET', url, **kwargs)
File "/Users/username/anaconda3/lib/python3.7/site-packages/requests/sessions.py", line 533, in request
resp = self.send(prep, **send_kwargs)
File "/Users/username/anaconda3/lib/python3.7/site-packages/requests/sessions.py", line 646, in send
r = adapter.send(request, **kwargs)
File "/Users/username/anaconda3/lib/python3.7/site-packages/requests/adapters.py", line 449, in send
timeout=timeout
File "/Users/username/anaconda3/lib/python3.7/site-packages/urllib3/connectionpool.py", line 600, in urlopen
chunked=chunked)
File "/Users/username/anaconda3/lib/python3.7/site-packages/urllib3/connectionpool.py", line 393, in _make_request
httplib_response.length)
Message: '%s://%s:%s "%s %s %s" %s %s'
Arguments: ('https', 'fapi.binance.com', 443, 'POST', '/fapi/v1/order?symbol=ETHUSDT&side=SELL&type=MARKET&quantity=0.01&newOrderRespType=RESULT×tamp=1630094894451&signature=67252a93834cedde133ad0fa62683126a9ca583147fffcf2cefbdff071fa4ce3', 'HTTP/1.1', 200, None)
--- Logging error ---
Traceback (most recent call last):
File "/Users/username/anaconda3/lib/python3.7/logging/__init__.py", line 1038, in emit
self.flush()
File "/Users/username/anaconda3/lib/python3.7/logging/__init__.py", line 1018, in flush
self.stream.flush()
PermissionError: [Errno 13] Permission denied
Call stack:
File "/Users/username/anaconda3/lib/python3.7/threading.py", line 885, in _bootstrap
self._bootstrap_inner()
File "/Users/username/anaconda3/lib/python3.7/threading.py", line 917, in _bootstrap_inner
self.run()
File "/Users/username/anaconda3/lib/python3.7/threading.py", line 865, in run
self._target(*self._args, **self._kwargs)
File "/Users/username/Workfiles/python/binance/vs_binance_algo/ETH_LinReg/engine_LinReg.py", line 102, in execute
execution_short_ETH.main()
File "/Users/username/Workfiles/python/binance/vs_binance_algo/ETH_LinReg/execution_short_ETH.py", line 58, in main
TP = int(entryPrice-settings_ETH.TP)
File "/Users/username/Workfiles/python/binance/vs_binance_algo/ETH_LinReg/send_requests_ETH.py", line 49, in send_signed_request
response = dispatch_request(http_method)(**params)
File "/Users/username/anaconda3/lib/python3.7/site-packages/requests/sessions.py", line 546, in get
return self.request('GET', url, **kwargs)
File "/Users/username/anaconda3/lib/python3.7/site-packages/requests/sessions.py", line 533, in request
resp = self.send(prep, **send_kwargs)
File "/Users/username/anaconda3/lib/python3.7/site-packages/requests/sessions.py", line 646, in send
r = adapter.send(request, **kwargs)
File "/Users/username/anaconda3/lib/python3.7/site-packages/requests/adapters.py", line 449, in send
timeout=timeout
File "/Users/username/anaconda3/lib/python3.7/site-packages/urllib3/connectionpool.py", line 588, in urlopen
conn = self._get_conn(timeout=pool_timeout)
File "/Users/username/anaconda3/lib/python3.7/site-packages/urllib3/connectionpool.py", line 248, in _get_conn
return conn or self._new_conn()
File "/Users/username/anaconda3/lib/python3.7/site-packages/urllib3/connectionpool.py", line 813, in _new_conn
self.num_connections, self.host, self.port or "443")
...and so on...
I can't find anything in the dev.binance forum in this regard (and they are anyway not very helpful).
What does this error mean?
My intuition is an imported module try to create a log file with logging module and raise a PermissionError.
Try to disable logging:
import logging.config
logging.config.dictConfig({
'version': 1,
'disable_existing_loggers': True,
})
I'm trying to stream m4a file over http using a simple wsgi server in python.
My code is like this:
mp3file = urllib2.urlopen(media_url)
data = mp3file.read()
headers = [('Content-type', 'audio/mp4'), ('Accept-Ranges', 'bytes')]
write = start_response('200 OK', headers)
write(data)
The problem is that if I set 'Content-Length' header like below, the client (Chrome browser for example) doesn't play the media. And if I don't set this header, it does play the media, but it doesn't know the length of the media so I can't seek/fast forward over the media file.
headers = [('Content-type', 'audio/mp4'), ('Content-Length', mp3file.headers['Content-Length']), ('Accept-Ranges', 'bytes')]
When setting the header I get this on console:
Traceback (most recent call last):
File "C:\Python27\lib\wsgiref\handlers.py", line 86, in run
self.finish_response()
File "C:\Python27\lib\wsgiref\handlers.py", line 128, in finish_response
self.write(data)
File "C:\Python27\lib\wsgiref\handlers.py", line 217, in write
self._write(data)
File "C:\Python27\lib\socket.py", line 324, in write
self.flush()
File "C:\Python27\lib\socket.py", line 303, in flush
self._sock.sendall(view[write_offset:write_offset+buffer_size])
error: [Errno 10053] An established connection was aborted by the software in your host machine
127.0.0.1 - - [28/Sep/2015 16:37:20] "GET /?yb=QfCqNbzJi3k HTTP/1.1" 500 59
Traceback (most recent call last):
File "C:\Python27\lib\SocketServer.py", line 295, in _handle_request_noblock
self.process_request(request, client_address)
File "C:\Python27\lib\SocketServer.py", line 321, in process_request
self.finish_request(request, client_address)
File "C:\Python27\lib\SocketServer.py", line 334, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "C:\Python27\lib\SocketServer.py", line 653, in __init__
self.finish()
File "C:\Python27\lib\SocketServer.py", line 712, in finish
self.wfile.close()
File "C:\Python27\lib\socket.py", line 279, in close
self.flush()
File "C:\Python27\lib\socket.py", line 303, in flush
self._sock.sendall(view[write_offset:write_offset+buffer_size])
error: [Errno 10053] An established connection was aborted by the software in your host machine
import webapp2
import mysql.connector
class MainHandler(webapp2.RequestHandler):
def get(self):
db=mysql.connector.connect(host="localhost",user="root",password="bsit",database="registration")
mycursor=db.cursor()
mycursor.execute("select * from student")
result=mycursor.fetchall()
self.response.write(str(result))
app = webapp2.WSGIApplication([('/', MainHandler)], debug=True)
Internal Server Error
The server has either erred or is incapable of performing the requested operation.
Traceback (most recent call last):
File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.5.2\webapp2.py", line 1535, in __call__
rv = self.handle_exception(request, response, e)
File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.5.2\webapp2.py", line 1529, in __call__
rv = self.router.dispatch(request, response)
File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.5.2\webapp2.py", line 1278, in default_dispatcher
return route.handler_adapter(request, response)
File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.5.2\webapp2.py", line 1102, in __call__
return handler.dispatch()
File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.5.2\webapp2.py", line 572, in dispatch
return self.handle_exception(e, self.app.debug)
File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.5.2\webapp2.py", line 570, in dispatch
return method(*args, **kwargs)
File "C:\Users\Aaqib Nadeem\Desktop\db-test\main.py", line 6, in get
db=mysql.connector.connect(host="localhost",user="root",password="bsit",database="registration")
File "C:\Python27\lib\mysql\connector\__init__.py", line 162, in connect
return MySQLConnection(*args, **kwargs)
File "C:\Python27\lib\mysql\connector\connection.py", line 129, in __init__
self.connect(**kwargs)
File "C:\Python27\lib\mysql\connector\connection.py", line 454, in connect
self._open_connection()
File "C:\Python27\lib\mysql\connector\connection.py", line 418, in _open_connection
self._do_handshake()
File "C:\Python27\lib\mysql\connector\connection.py", line 141, in _do_handshake
packet = self._socket.recv()
File "C:\Python27\lib\mysql\connector\network.py", line 255, in recv_plain
errno=2055, values=(self.get_address(), _strioerror(err)))
OperationalError: 2055: Lost connection to MySQL server at 'localhost:3306', system error:
Please provide a solution of this error
There is no way to use MySQL with Google App Engine. You can use GAE Cloud SQL instead.
Here is the code:
conn = httplib.HTTPConnection("127.0.0.1:8000")
conn.request("POST", "/api/job/", some_params, headers)
conn.close()
no problem with sending request to server
but if i use loop for example:
for i in range(n):
conn = httplib.HTTPConnection("127.0.0.1:8000")
conn.request("POST", "/api/job/", some_params, headers)
conn.close()
it rises an exception, but it is interesting that request is successfull:
Traceback (most recent call last):
File "/usr/lib/python2.7/site-packages/django/core/servers/basehttp.py", line 284, in run
self.finish_response()
File "/usr/lib/python2.7/site-packages/django/core/servers/basehttp.py", line 324, in finish_response
self.write(data)
File "/usr/lib/python2.7/site-packages/django/core/servers/basehttp.py", line 403, in write
self.send_headers()
File "/usr/lib/python2.7/site-packages/django/core/servers/basehttp.py", line 467, in send_headers
self.send_preamble()
File "/usr/lib/python2.7/site-packages/django/core/servers/basehttp.py", line 385, in send_preamble
'Date: %s\r\n' % http_date()
File "/usr/lib/python2.7/socket.py", line 324, in write
self.flush()
File "/usr/lib/python2.7/socket.py", line 303, in flush
self._sock.sendall(view[write_offset:write_offset+buffer_size])
error: [Errno 32] Broken pipe
----------------------------------------
Exception happened during processing of request from ('127.0.0.1', 60438)
Traceback (most recent call last):
File "/usr/lib/python2.7/SocketServer.py", line 284, in _handle_request_noblock
self.process_request(request, client_address)
File "/usr/lib/python2.7/SocketServer.py", line 310, in process_request
self.finish_request(request, client_address)
File "/usr/lib/python2.7/SocketServer.py", line 323, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "/usr/lib/python2.7/site-packages/django/core/servers/basehttp.py", line 570, in __init__
BaseHTTPRequestHandler.__init__(self, *args, **kwargs)
File "/usr/lib/python2.7/SocketServer.py", line 641, in __init__
self.finish()
File "/usr/lib/python2.7/SocketServer.py", line 694, in finish
self.wfile.flush()
File "/usr/lib/python2.7/socket.py", line 303, in flush
self._sock.sendall(view[write_offset:write_offset+buffer_size])
error: [Errno 32] Broken pipe
----------------------------------------
any suggestions ???
Looks to me like your buffer is getting filled. Your buffer will fill with any network requests you make, then is cleared when the server acknowledges receipt of the data. Not sure if there isn't a better way to do this, but you could try giving the server some time to acknowledge receipt by doing a short time.pause within your loop.