Unable to send json request when using fastapi - json

I have error in the following code when I try to send a request with json data in it, is it because it only works synchronously, so does not work in fastapi which work asynchronously? If that is the case, what is the simplest way to send a request with json data in it?
import time
from fastapi import Request, FastAPI, BackgroundTasks
import multiprocessing as mp
import uvicorn
import requests
import json
def printmessage(job):
time.sleep(5)
print(job)
if __name__ == 'webhook_fastapi':
url = 'http://127.0.0.1:8000/webhook'
data = { 'text': 'hello'}
r = requests.post(url, data=json.dumps(data), headers={'Content-Type': 'application/json'})
print("Request Sent!")
app = FastAPI()
#app.post("/webhook")
async def webhook(request : Request, background_tasks: BackgroundTasks):
print("WEBHOOK RECEIVED")
job="doctor"
background_tasks.add_task(printmessage,job)
print('done')
return 'WEBHOOK RECEIVED'
if __name__ == '__main__':
print("PROGRAM LAUNCH...")
print("WEBHOOK RECEIVE READY...")
background_tasks = BackgroundTasks()
job="doctor"
background_tasks.add_task(printmessage,job)
uvicorn.run("webhook_fastapi:app", reload=False)
OUTPUT:
__main__
PROGRAM LAUNCH...
WEBHOOK RECEIVE READY...
webhook_fastapi
Traceback (most recent call last): File
"C:\Users\User\AppData\Local\Programs\Python\Python39\lib\site-packages\urllib3\connection.py",
line 169, in _new_conn
conn = connection.create_connection( File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\site-packages\urllib3\util\connection.py",
line 96, in create_connection
raise err File "C:\Users\User\AppData\Local\Programs\Python\Python39\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\User\AppData\Local\Programs\Python\Python39\lib\site-packages\urllib3\connectionpool.py",
line 699, in urlopen
httplib_response = self._make_request( File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\site-packages\urllib3\connectionpool.py",
line 394, in _make_request
conn.request(method, url, **httplib_request_kw) File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\site-packages\urllib3\connection.py",
line 234, in request
super(HTTPConnection, self).request(method, url, body=body, headers=headers) File
"C:\Users\User\AppData\Local\Programs\Python\Python39\lib\http\client.py",
line 1279, in request
self._send_request(method, url, body, headers, encode_chunked) File
"C:\Users\User\AppData\Local\Programs\Python\Python39\lib\http\client.py",
line 1325, in _send_request
self.endheaders(body, encode_chunked=encode_chunked) File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\http\client.py",
line 1274, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked) File
"C:\Users\User\AppData\Local\Programs\Python\Python39\lib\http\client.py",
line 1034, in _send_output
self.send(msg) File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\http\client.py",
line 974, in send
self.connect() File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\site-packages\urllib3\connection.py",
line 200, in connect
conn = self._new_conn() File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\site-packages\urllib3\connection.py",
line 181, in _new_conn
raise NewConnectionError( urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnection object at 0x0000013C0E494310>:
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\User\AppData\Local\Programs\Python\Python39\lib\site-packages\requests\adapters.py",
line 439, in send
resp = conn.urlopen( File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\site-packages\urllib3\connectionpool.py",
line 755, in urlopen
retries = retries.increment( File "C:\Users\User\AppData\Local\Programs\Python\Python39\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=8000): Max retries exceeded with url: /webhook (Caused by
NewConnectionError('<urllib3.connection.HTTPConnection object at
0x0000013C0E494310>: 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*\webhook_fastapi.py", line 40, in
uvicorn.run("webhook_fastapi:app", reload=False) File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\site-packages\uvicorn\main.py",
line 463, in run
server.run() File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\site-packages\uvicorn\server.py",
line 60, in run
return asyncio.run(self.serve(sockets=sockets)) File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\asyncio\runners.py",
line 44, in run
return loop.run_until_complete(main) File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\asyncio\base_events.py",
line 642, in run_until_complete
return future.result() File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\site-packages\uvicorn\server.py",
line 67, in serve
config.load() File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\site-packages\uvicorn\config.py",
line 458, in load
self.loaded_app = import_from_string(self.app) File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\site-packages\uvicorn\importer.py",
line 21, in import_from_string
module = importlib.import_module(module_str) File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\importlib_init_.py",
line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level) File "", line 1030, in _gcd_import File
"", line 1007, in _find_and_load File
"", line 986, in _find_and_load_unlocked
File "", line 680, in _load_unlocked
File "", line 850, in
exec_module File "", line 228, in
_call_with_frames_removed File "c:\Users*\webhook_fastapi.py", line 19, in
r = requests.post(url, data=json.dumps(data), headers={'Content-Type': 'application/json'}) File
"C:\Users\User\AppData\Local\Programs\Python\Python39\lib\site-packages\requests\api.py",
line 117, in post
return request('post', url, data=data, json=json, **kwargs) File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\site-packages\requests\api.py",
line 61, in request
return session.request(method=method, url=url, **kwargs) File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\site-packages\requests\sessions.py",
line 542, in request
resp = self.send(prep, **send_kwargs) File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\site-packages\requests\sessions.py",
line 655, in send
r = adapter.send(request, kwargs) File "C:\Users\User\AppData\Local\Programs\Python\Python39\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=8000): Max retries exceeded
with url: /webhook (Caused by
NewConnectionError('<urllib3.connection.HTTPConnection object at
0x0000013C0E494310>: Failed to establish a new connection: [WinError
10061] No connection could be made because the target machine actively
refused it')) PS C:\Users*>

There is no server running when you're trying to make your request. uvicorn is importing your code, and you're apparently trying to make a request while the code is being imported.
uvicorn can't launch the API and bind to the port before it has finished importing the code and the ASGI application has been set up and properly configured.

Related

Connection refused when switching TPU version

How can I switch TPU version for TPU VM architechture?
When attempting to switch software version for TPU(TPU VM architechture switching from tpu-vm-tf-2.6.0-pod to tpu-vm-base) using instructions found here, I get Connection Refused exception with traceback:
Traceback (most recent call last):
File "/usr/lib/python3.8/urllib/request.py", line 1354, in do_open
h.request(req.get_method(), req.selector, req.data, headers,
File "/usr/lib/python3.8/http/client.py", line 1256, in request
self._send_request(method, url, body, headers, encode_chunked)
File "/usr/lib/python3.8/http/client.py", line 1302, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "/usr/lib/python3.8/http/client.py", line 1251, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "/usr/lib/python3.8/http/client.py", line 1011, in _send_output
self.send(msg)
File "/usr/lib/python3.8/http/client.py", line 951, in send
self.connect()
File "/usr/lib/python3.8/http/client.py", line 922, in connect
self.sock = self._create_connection(
File "/usr/lib/python3.8/socket.py", line 808, in create_connection
raise err
File "/usr/lib/python3.8/socket.py", line 796, in create_connection
sock.connect(sa)
ConnectionRefusedError: [Errno 111] Connection refused
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "switch.py", line 20, in <module>
c.configure_tpu_version(args.target_version, restart_type="ifNeeded")
File "/usr/local/lib/python3.8/dist-packages/cloud_tpu_client/client.py", line 391, in configure_tpu_version
for result in results:
File "/usr/lib/python3.8/concurrent/futures/_base.py", line 619, in result_iterator
yield fs.pop().result()
File "/usr/lib/python3.8/concurrent/futures/_base.py", line 444, in result
return self.__get_result()
File "/usr/lib/python3.8/concurrent/futures/_base.py", line 389, in __get_result
raise self._exception
File "/usr/lib/python3.8/concurrent/futures/thread.py", line 57, in run
result = self.fn(*self.args, **self.kwargs)
File "/usr/local/lib/python3.8/dist-packages/cloud_tpu_client/client.py", line 375, in configure_worker
request.urlopen(req)
File "/usr/lib/python3.8/urllib/request.py", line 222, in urlopen
return opener.open(url, data, timeout)
File "/usr/lib/python3.8/urllib/request.py", line 525, in open
response = self._open(req, data)
File "/usr/lib/python3.8/urllib/request.py", line 542, in _open
result = self._call_chain(self.handle_open, protocol, protocol +
File "/usr/lib/python3.8/urllib/request.py", line 502, in _call_chain
result = func(*args)
File "/usr/lib/python3.8/urllib/request.py", line 1383, in http_open
return self.do_open(http.client.HTTPConnection, req)
File "/usr/lib/python3.8/urllib/request.py", line 1357, in do_open
raise URLError(err)
urllib.error.URLError: <urlopen error [Errno 111] Connection refused>
The command is run on cloud TPU VM with cloud-tpu-client version 0.10
When running the same command from my PC I get Connection timed out after a long pause with traceback:
Traceback (most recent call last):
File "/home/nevus/anaconda3/envs/imageGen/lib/python3.7/urllib/request.py", line 1350, in do_open
encode_chunked=req.has_header('Transfer-encoding'))
File "/home/nevus/anaconda3/envs/imageGen/lib/python3.7/http/client.py", line 1281, in request
self._send_request(method, url, body, headers, encode_chunked)
File "/home/nevus/anaconda3/envs/imageGen/lib/python3.7/http/client.py", line 1327, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "/home/nevus/anaconda3/envs/imageGen/lib/python3.7/http/client.py", line 1276, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "/home/nevus/anaconda3/envs/imageGen/lib/python3.7/http/client.py", line 1036, in _send_output
self.send(msg)
File "/home/nevus/anaconda3/envs/imageGen/lib/python3.7/http/client.py", line 976, in send
self.connect()
File "/home/nevus/anaconda3/envs/imageGen/lib/python3.7/http/client.py", line 948, in connect
(self.host,self.port), self.timeout, self.source_address)
File "/home/nevus/anaconda3/envs/imageGen/lib/python3.7/socket.py", line 728, in create_connection
raise err
File "/home/nevus/anaconda3/envs/imageGen/lib/python3.7/socket.py", line 716, in create_connection
sock.connect(sa)
TimeoutError: [Errno 110] Connection timed out
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "tpu_version.py", line 19, in <module>
c.configure_tpu_version(args.target_version, restart_type="ifNeeded")
File "/home/nevus/anaconda3/envs/imageGen/lib/python3.7/site-packages/cloud_tpu_client/client.py", line 392, in configure_tpu_version
for result in results:
File "/home/nevus/anaconda3/envs/imageGen/lib/python3.7/concurrent/futures/_base.py", line 598, in result_iterator
yield fs.pop().result()
File "/home/nevus/anaconda3/envs/imageGen/lib/python3.7/concurrent/futures/_base.py", line 435, in result
return self.__get_result()
File "/home/nevus/anaconda3/envs/imageGen/lib/python3.7/concurrent/futures/_base.py", line 384, in __get_result
raise self._exception
File "/home/nevus/anaconda3/envs/imageGen/lib/python3.7/concurrent/futures/thread.py", line 57, in run
result = self.fn(*self.args, **self.kwargs)
File "/home/nevus/anaconda3/envs/imageGen/lib/python3.7/site-packages/cloud_tpu_client/client.py", line 376, in configure_worker
request.urlopen(req)
File "/home/nevus/anaconda3/envs/imageGen/lib/python3.7/urllib/request.py", line 222, in urlopen
return opener.open(url, data, timeout)
File "/home/nevus/anaconda3/envs/imageGen/lib/python3.7/urllib/request.py", line 525, in open
response = self._open(req, data)
File "/home/nevus/anaconda3/envs/imageGen/lib/python3.7/urllib/request.py", line 543, in _open
'_open', req)
File "/home/nevus/anaconda3/envs/imageGen/lib/python3.7/urllib/request.py", line 503, in _call_chain
result = func(*args)
File "/home/nevus/anaconda3/envs/imageGen/lib/python3.7/urllib/request.py", line 1378, in http_open
return self.do_open(http.client.HTTPConnection, req)
File "/home/nevus/anaconda3/envs/imageGen/lib/python3.7/urllib/request.py", line 1352, in do_open
raise URLError(err)
urllib.error.URLError: <urlopen error [Errno 110] Connection timed out>
This feature is not supported by the TPU VM architecture.
Best way to change the TPU VM's version would be to delete it and recreate a new one with the desired version.

I am getting Expected Ptr<cv::UMat> for argument 'src' error while running ocr python file. Below attached is the full error message

it is working fine in my local system but when running from pythonanywhere.com, i am getting this error.
Traceback (most recent call last):
File "/home/clonesangram/.virtualenvs/django3/lib/python3.8/site-packages/django/core/handlers/exception.py", line 47, in inner
response = get_response(request)
File "/home/clonesangram/.virtualenvs/django3/lib/python3.8/site-packages/django/core/handlers/base.py", line 181, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/clonesangram/django_projects/ocrsite/ocr/views.py", line 187, in image_upload_view
return render(request, 'ocr/index1.html', {'form': form, 'img_obj': img_obj, 'text': text_detector(image)})
File "/home/clonesangram/django_projects/ocrsite/ocr/Test_OCR_Img.py", line 15, in text_detector
image = cv2.resize(np.float32(image), (320, 320), interpolation=cv2.INTER_AREA)
Exception Type: TypeError at /ocr/upload/
Exception Value: Expected Ptr<cv::UMat> for argument 'src'

"Lost connection to MySQL server during query python

I am using #transaction.atomic decorator
I am using python and django
and I got this error:
Internal Server Error: /create_project
Traceback (most recent call last):
File "/usr/local/lib/python3.4/dist-packages/django/db/backends/base/base.py", line 239, in _commit
return self.connection.commit()
File "/usr/local/lib/python3.4/dist-packages/pymysql/connections.py", line 422, in commit
self._read_ok_packet()
File "/usr/local/lib/python3.4/dist-packages/pymysql/connections.py", line 396, in _read_ok_packet
pkt = self._read_packet()
File "/usr/local/lib/python3.4/dist-packages/pymysql/connections.py", line 656, in _read_packet
packet_header = self._read_bytes(4)
File "/usr/local/lib/python3.4/dist-packages/pymysql/connections.py", line 702, in _read_bytes
CR.CR_SERVER_LOST, "Lost connection to MySQL server during query")
pymysql.err.OperationalError: (2013, 'Lost connection to MySQL server during query')
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/usr/local/lib/python3.4/dist-packages/django/core/handlers/exception.py", line 35, in inner
response = get_response(request)
File "/usr/local/lib/python3.4/dist-packages/django/core/handlers/base.py", line 128, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/usr/local/lib/python3.4/dist-packages/django/core/handlers/base.py", line 126, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/usr/lib/python3.4/contextlib.py", line 30, in inner
return func(*args, **kwds)
File "/usr/local/lib/python3.4/dist-packages/django/db/transaction.py", line 212, in __exit__
connection.commit()
File "/usr/local/lib/python3.4/dist-packages/django/db/backends/base/base.py", line 261, in commit
self._commit()
File "/usr/local/lib/python3.4/dist-packages/django/db/backends/base/base.py", line 239, in _commit
return self.connection.commit()
File "/usr/local/lib/python3.4/dist-packages/django/db/utils.py", line 89, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/usr/local/lib/python3.4/dist-packages/django/db/backends/base/base.py", line 239, in _commit
return self.connection.commit()
File "/usr/local/lib/python3.4/dist-packages/pymysql/connections.py", line 422, in commit
self._read_ok_packet()
File "/usr/local/lib/python3.4/dist-packages/pymysql/connections.py", line 396, in _read_ok_packet
pkt = self._read_packet()
File "/usr/local/lib/python3.4/dist-packages/pymysql/connections.py", line 656, in _read_packet
packet_header = self._read_bytes(4)
File "/usr/local/lib/python3.4/dist-packages/pymysql/connections.py", line 702, in _read_bytes
CR.CR_SERVER_LOST, "Lost connection to MySQL server during query")
django.db.utils.OperationalError: (2013, 'Lost connection to MySQL server during query')
What do I do??
UPD: I am using cloud 9 ide (c9.io) so can this be connected to performance issue since the c9 servers are not so robust?

Django + SSL + mysql: TypeError: __init__() got an unexpected keyword argument 'server_hostname'

I used Djano to build a simple restful API server. SSL has been introduced to the communication between the server and the remote database to enforce security. When the API server tried to write to the database, I got the following error:
File "/app/anaconda/lib/python2.7/site-packages/django/core/handlers/exception.py", line 39, in inner
response = get_response(request)
File "/app/anaconda/lib/python2.7/site-packages/django/core/handlers/base.py", line 187, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/app/anaconda/lib/python2.7/site-packages/django/core/handlers/base.py", line 185, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/app/anaconda/lib/python2.7/site-packages/django/views/decorators/csrf.py", line 58, in wrapped_view
return view_func(*args, **kwargs)
File "/app/anaconda/lib/python2.7/site-packages/django/views/generic/base.py", line 68, in view
return self.dispatch(request, *args, **kwargs)
File "/app/anaconda/lib/python2.7/site-packages/rest_framework/views.py", line 474, in dispatch
response = self.handle_exception(exc)
File "/app/anaconda/lib/python2.7/site-packages/rest_framework/views.py", line 434, in handle_exception
self.raise_uncaught_exception(exc)
File "/app/anaconda/lib/python2.7/site-packages/rest_framework/views.py", line 471, in dispatch
response = handler(request, *args, **kwargs)
File "/app/anaconda/lib/python2.7/site-packages/rest_framework/decorators.py", line 52, in handler
return func(*args, **kwargs)
File "/app/mobile/mpq_backup_response/mpq_backup_response/backup_response/views.py", line 39, in sms
q.save()
File "/app/anaconda/lib/python2.7/site-packages/django/db/models/base.py", line 796, in save
force_update=force_update, update_fields=update_fields)
File "/app/anaconda/lib/python2.7/site-packages/django/db/models/base.py", line 821, in save_base
with transaction.atomic(using=using, savepoint=False):
File "/app/anaconda/lib/python2.7/site-packages/django/db/transaction.py", line 158, in __enter__
if not connection.get_autocommit():
File "/app/anaconda/lib/python2.7/site-packages/django/db/backends/base/base.py", line 365, in get_autocommit
self.ensure_connection()
File "/app/anaconda/lib/python2.7/site-packages/django/db/backends/base/base.py", line 199, in ensure_connection
self.connect()
File "/app/anaconda/lib/python2.7/site-packages/django/db/backends/base/base.py", line 171, in connect
self.connection = self.get_new_connection(conn_params)
File "/app/anaconda/lib/python2.7/site-packages/django/db/backends/mysql/base.py", line 265, in get_new_connection
conn = Database.connect(**conn_params)
File "/app/anaconda/lib/python2.7/site-packages/pymysql/__init__.py", line 90, in Connect
return Connection(*args, **kwargs)
File "/app/anaconda/lib/python2.7/site-packages/pymysql/connections.py", line 688, in __init__
self.connect()
File "/app/anaconda/lib/python2.7/site-packages/pymysql/connections.py", line 906, in connect
self._request_authentication()
File "/app/anaconda/lib/python2.7/site-packages/pymysql/connections.py", line 1086, in _request_authentication
self._sock = self.ctx.wrap_socket(self._sock, server_hostname=self.host)
File "/app/anaconda/lib/python2.7/ssl.py", line 352, in wrap_socket
_context=self)
TypeError: __init__() got an unexpected keyword argument 'server_hostname'
However, if I went into Djangon's shell interactive environment and wrote directly into the database, everything went smoothly. I don't why this problem happens.
This issue seems to exist in OS X with python 2.7.10 and according to the link below, you will most likely run into this with CentOS 7 and Python ver 2.7.9 or above.
https://github.com/gevent/gevent/issues/477
Updating gevent to 1.2.1 seems to solve the problem.
You could run "pip install --upgrade gevent" on mac to fix this.

SQLAlchemy with Google Cloud SQL connect to development server

I am using SQLAlchemy 0.8 with Google App Engine and Cloud SQL. I would like to do a full integration test locally before deploying, but I cannot get SQLAlchemy to connect to my development MySQL server using the mysql+gaerdbms dialect
create_engine(
'mysql+gaerdbms:///test?instance=homingbox:instance1'
)
I start my app engine from the command line as follows
python dev_appserver.py --mysql_user=username --mysql_password=root ../Source/HomingBox/gae
Whenever I try to hit the database I get this lovely stack trace
ERROR 2013-04-22 21:35:39,987 webapp2.py:1528] (ImportError) None None
Traceback (most recent call last):
File "/home/leon/Development/google_appengine/lib/webapp2-2.3/webapp2.py", line 1511, in __call__
rv = self.handle_exception(request, response, e)
File "/home/leon/Development/google_appengine/lib/webapp2-2.3/webapp2.py", line 1505, in __call__
rv = self.router.dispatch(request, response)
File "/home/leon/Development/google_appengine/lib/webapp2-2.3/webapp2.py", line 1253, in default_dispatcher
return route.handler_adapter(request, response)
File "/home/leon/Development/google_appengine/lib/webapp2-2.3/webapp2.py", line 1077, in __call__
return handler.dispatch()
File "/home/leon/Development/google_appengine/lib/webapp2-2.3/webapp2.py", line 547, in dispatch
return self.handle_exception(e, self.app.debug)
File "/home/leon/Development/google_appengine/lib/webapp2-2.3/webapp2.py", line 545, in dispatch
return method(*args, **kwargs)
File "/home/leon/Development/Source/HomingBox/gae/rest.py", line 19, in get_list
self.response.write(json.dumps(application.get_list()))
File "/home/leon/Development/Source/HomingBox/gae/dal.py", line 98, in get_list
return query.all()
File "/home/leon/Development/Source/HomingBox/gae/sqlalchemy/orm/query.py", line 2140, in all
return list(self)
File "/home/leon/Development/Source/HomingBox/gae/sqlalchemy/orm/query.py", line 2252, in __iter__
return self._execute_and_instances(context)
File "/home/leon/Development/Source/HomingBox/gae/sqlalchemy/orm/query.py", line 2265, in _execute_and_instances
close_with_result=True)
File "/home/leon/Development/Source/HomingBox/gae/sqlalchemy/orm/query.py", line 2256, in _connection_from_session
**kw)
File "/home/leon/Development/Source/HomingBox/gae/sqlalchemy/orm/session.py", line 797, in connection
close_with_result=close_with_result)
File "/home/leon/Development/Source/HomingBox/gae/sqlalchemy/orm/session.py", line 801, in _connection_for_bind
return self.transaction._connection_for_bind(engine)
File "/home/leon/Development/Source/HomingBox/gae/sqlalchemy/orm/session.py", line 297, in _connection_for_bind
conn = bind.contextual_connect()
File "/home/leon/Development/Source/HomingBox/gae/sqlalchemy/engine/base.py", line 1669, in contextual_connect
self.pool.connect(),
File "/home/leon/Development/Source/HomingBox/gae/sqlalchemy/pool.py", line 272, in connect
return _ConnectionFairy(self).checkout()
File "/home/leon/Development/Source/HomingBox/gae/sqlalchemy/pool.py", line 425, in __init__
rec = self._connection_record = pool._do_get()
File "/home/leon/Development/Source/HomingBox/gae/sqlalchemy/pool.py", line 855, in _do_get
return self._create_connection()
File "/home/leon/Development/Source/HomingBox/gae/sqlalchemy/pool.py", line 225, in _create_connection
return _ConnectionRecord(self)
File "/home/leon/Development/Source/HomingBox/gae/sqlalchemy/pool.py", line 318, in __init__
self.connection = self.__connect()
File "/home/leon/Development/Source/HomingBox/gae/sqlalchemy/pool.py", line 368, in __connect
connection = self.__pool._creator()
File "/home/leon/Development/Source/HomingBox/gae/sqlalchemy/engine/strategies.py", line 80, in connect
return dialect.connect(*cargs, **cparams)
File "/home/leon/Development/Source/HomingBox/gae/sqlalchemy/engine/default.py", line 279, in connect
return self.dbapi.connect(*cargs, **cparams)
File "/home/leon/Development/google_appengine/google/storage/speckle/python/api/rdbms_googleapi.py", line 183, in __init__
super(GoogleApiConnection, self).__init__(*args, **kwargs)
File "/home/leon/Development/google_appengine/google/storage/speckle/python/api/rdbms.py", line 810, in __init__
self.OpenConnection()
File "/home/leon/Development/google_appengine/google/storage/speckle/python/api/rdbms.py", line 832, in OpenConnection
self.SetupClient()
File "/home/leon/Development/google_appengine/google/storage/speckle/python/api/rdbms_googleapi.py", line 193, in SetupClient
self._client = RdbmsGoogleApiClient(**kwargs)
File "/home/leon/Development/google_appengine/google/storage/speckle/python/api/rdbms_googleapi.py", line 106, in __init__
rdbms.OAUTH_CREDENTIALS_PATH)
File "/usr/lib/python2.7/posixpath.py", line 268, in expanduser
import pwd
File "/home/leon/Development/google_appengine/google/appengine/tools/devappserver2/python/sandbox.py", line 827, in load_module
raise ImportError
Any help is much appreciated
Here's my hypothesis, based on the stack trace -- when the application can't find your HOME directory, it attempts to import pwd and get the home directory information that way. The application is trying to call this bit of code in posixpath.py:
if 'HOME' not in os.environ:
import pwd
userhome = pwd.getpwuid(os.getuid()).pw_dir
else:
userhome = os.environ['HOME']
Except, I don't think that GAE will allow pwd to be imported for security reasons. The sandbox environment doesn't look to have it included in its whitelist of allowed modules, and raises an ImportError if the modules aren't in that list.
If I attempt to just do an import pwd inside of a regular handler module, GAE won't allow it.