Advertisement
Guest User

Untitled

a guest
Feb 19th, 2019
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.37 KB | None | 0 0
  1. from google.appengine.ext.remote_api import remote_api_stub
  2.  
  3. def test_remote_api():
  4. # This function is called when I want to use the remote api instead of the local datastore access
  5. remote_api_stub.ConfigureRemoteApi('myapp.appspot.com', '/_ah/remote_api', auth_func, '')
  6.  
  7. def auth_func:
  8. # This actually returns a tuple with my credentials to skip the console input
  9. return ('username', 'password')
  10.  
  11. File "C:Program Files(x86)Googlegoogle_appenginegoogleappenginetoolsdev_appserver_blobstore.py", line 79, in GetBlobStorage
  12. return apiproxy_stub_map.apiproxy.GetStub('blobstore').storage
  13. AttributeError: 'RemoteStub' object has no attribute 'storage'
  14.  
  15. def attach_to_app(app_id, user=None, password=None, path=None, address=None):
  16. """
  17. attaches to app_id instance at address (default: <app_id>.appspot.com)
  18.  
  19. if you don't specify a user/password you will be prompted for one
  20.  
  21. if you don't specify an address it is assumed to be
  22. <app_id>.appspot.com
  23.  
  24. path: path to remote_api handler, if not
  25. specified, will use /_ah/remote_api
  26. """
  27. path = path or "/_ah/remote_api"
  28.  
  29. if not address:
  30. address = "%s.appspot.com" % app_id
  31.  
  32. init_remote_api(app_id, path, address, user=user, password=password)
  33.  
  34.  
  35.  
  36.  
  37. def auth_func():
  38. """
  39. function to prompt user for credentials
  40. """
  41. email_address = raw_input("Email Address: ")
  42. password = getpass.getpass("Password: ")
  43. return email_address, password
  44.  
  45.  
  46. def init_remote_api(app_id, path, address, user=None, password=None):
  47. """
  48. generic wrapper to initialize the remoteapi for a given path
  49.  
  50. required
  51. =========
  52. app_id : the app_id of the application to connect to
  53. path: the path to the remote_api handler ex: /_ah/remote_api
  54. address: server to connect to ex: myapp.appspot.com
  55.  
  56. if user and password are not specified you will be prompted on
  57. connection if needed
  58. """
  59. if user and password:
  60. def my_auth():
  61. return (user, password)
  62. else:
  63. my_auth = auth_func
  64.  
  65. remote_api_stub.ConfigureRemoteApi(app_id, path, my_auth, address)
  66. remote_api_stub.MaybeInvokeAuthentication()
  67. os.environ["SERVER_SOFTWARE"] = "Development (remote_api)/1.0"
  68.  
  69. # example
  70. APP_ID = "s~myapp" # when hrds was introduced it became necessary to specify app_id and address note the "s~..."
  71. ADDRESS = "myapp.appspot.com"
  72. attach_to_app(APP_ID, address=ADDRESS)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement