webapp2

Pymongo/bson: Convert python.cursor.Cursor object to serializable/JSON object

一曲冷凌霜 提交于 2019-12-03 11:29:41
问题 New to MongoDb and Python ( webapp2 ). So, I was fetching some data from a mongodb database. But I was unable to use json.dumps on the returned data. Here's my code: exchangedata = db.Stock_Master.find({"Country": "PHILIPPINES"}, {"_id" : 0}) self.response.write(json.dumps(exchangedata)) This throws an error: TypeError: pymongo.cursor.Cursor object at 0x7fcd51230290 is not JSON serializable The type of exchangedata is pymongo.cursor.Cursor . How can I convert it into a json object? 回答1: Use

How do I make a trailing slash optional with webapp2?

杀马特。学长 韩版系。学妹 提交于 2019-12-03 09:55:06
I'm using the new webapp2 (now the default webapp in 1.6), and I haven't been able to figure out how to make the trailing slash optional in code like this: webapp.Route('/feed', handler = feed) I've tried /feed/? , /feed/* , /feed\/* and /feed\/? , all to no avail. Aneon To avoid creating duplicate URL:s to the same page, you should use a RedirectRoute with strict_slash set to True to automatically redirect /feed/ to /feed, like this: from webapp2_extras.routes import RedirectRoute route = RedirectRoute('/feed', handler=feed, strict_slash=True) Read more at http://webapp2.readthedocs.io/en

How to parse an Angular POST request in WebApp2

耗尽温柔 提交于 2019-12-03 07:04:53
How do I get data from my Angular POST request in Google App Engine WebApp2? self.request.body returns a string, and self.request.get(key) returns nothing. The Angular code that submits the POST is: $http.post("/mail", {request_name: 'Test Name', request_body: 'Test Body'}); Then these two lines in my WebApp2 handler: print "1: " + self.request.body print "2: " + self.request.get('request_name') Print this: 1: {"request_name":"Test Name","request_body":"Test Body"} 2: What is the best way get data from the POST body? Or should I send the request differently? dlebech Judging from your first

Django vs webapp2 on App Engine [closed]

佐手、 提交于 2019-12-03 06:09:58
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. I would like to know your opinion of which of these two web frameworks (Django & webapp2) is better for using on App Engine Platform, and why? Please don't say that both are completely different, because Django is much more complete. Both are the "web

Understanding global object persistence in Python WSGI apps

假装没事ソ 提交于 2019-12-03 02:33:00
Consider the following code in my WebApp2 application in Google App Engine: count = 0 class MyHandler(webapp2.RequestHandler): def get(self): global count count = count + 1 print count With each refresh of the page, the count increments higher. I'm coming from the PHP world where every request was a new global environment. What I understand to be happening here is, because I'm using the wsgi configuration for WebApp2, Python does not kick off a new process on each request. If I was using a cgi configuration, on the other hand, the global environment would re-instantiate each time, like PHP...

Pymongo/bson: Convert python.cursor.Cursor object to serializable/JSON object

笑着哭i 提交于 2019-12-03 01:52:48
New to MongoDb and Python ( webapp2 ). So, I was fetching some data from a mongodb database. But I was unable to use json.dumps on the returned data. Here's my code: exchangedata = db.Stock_Master.find({"Country": "PHILIPPINES"}, {"_id" : 0}) self.response.write(json.dumps(exchangedata)) This throws an error: TypeError: pymongo.cursor.Cursor object at 0x7fcd51230290 is not JSON serializable The type of exchangedata is pymongo.cursor.Cursor . How can I convert it into a json object? Use dumps from bson.json_util : >>> c = pymongo.MongoClient() >>> c.test.test.count() 5 >>> from bson.json_util

AppEngine: No module named pyasn1.compat.binary

£可爱£侵袭症+ 提交于 2019-12-02 04:29:48
I keep getting the following error when hitting my AppEngine server: ERROR 2017-09-20 07:16:06,978 wsgi.py:263] Traceback (most recent call last): File "/usr/lib/google-cloud-sdk/platform/google_appengine/google/appengine/runtime/wsgi.py", line 240, in Handle handler = _config_handle.add_wsgi_middleware(self._LoadHandler()) File "/usr/lib/google-cloud-sdk/platform/google_appengine/google/appengine/runtime/wsgi.py", line 299, in _LoadHandler handler, path, err = LoadObject(self._handler) File "/usr/lib/google-cloud-sdk/platform/google_appengine/google/appengine/runtime/wsgi.py", line 96, in

Webapp2 Sessions in Google app engine

二次信任 提交于 2019-12-01 20:19:21
问题 I just figured out how to implement the webapp2 sessions in my Google app engine project using python. The code is below. What I would like to know is what is the best approach to go about it? What I have done is created a python file and dropped the BaseHandler code in it then I simply import it but I have to constantly duplicate the config key in each python app/file. The code for the BaseHandler as I got from the website: class BaseHandler(webapp2.RequestHandler): def dispatch(self): # Get

How to handle sensitive configuration information when deploying app-engine applications?

孤街浪徒 提交于 2019-12-01 19:38:41
问题 Example: I have an applications that needs to access an API providing an authentication token myApi = MyApi(token=my_private_sensible_token) I want to avoid having that private token in a configuration file that is part of the project. One solution that comes to mind is to isolate interaction with this service in a separate proxy application that is maintained by a restricted number of authorised people. App-engine allows to protect handlers with authentication and I could easily, in the

Webapp2 Sessions in Google app engine

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-01 19:29:44
I just figured out how to implement the webapp2 sessions in my Google app engine project using python. The code is below. What I would like to know is what is the best approach to go about it? What I have done is created a python file and dropped the BaseHandler code in it then I simply import it but I have to constantly duplicate the config key in each python app/file. The code for the BaseHandler as I got from the website: class BaseHandler(webapp2.RequestHandler): def dispatch(self): # Get a session store for this request. self.session_store = sessions.get_store(request=self.request) try: #