Failed attempts-access data across apps in Gae

Source: Internet
Author: User

After uploading a lot of data to Gae last time, I began to consider how to use them. First, I had to solve the problem of cross-APP data access, because I applied for a lot of appid, I hope they can share data, which makes it much easier for me. Otherwise, it is very difficult for me to provide a query interface for every data and then access the interface in other apps.
Therefore, I have tried and studied this issue, and it is still in the failed State, because I started to write it during the study.ArticleI don't know if the research will be successful in the future. Although this issue is not officially stated in the Google documentation, I believe it can be done for the following reasons:
1. Gae is part of Google's "cloud" strategy. From the "cloud" concept, it should be able to share extensive data;
2. From the source code of Gae datastore, I found many parameters called _ app, indicating that this implementation may also be considered from the perspective of Google's design;
3. Google has launched the remote_api. Even if Google does not open the _ app parameter for the time being, I can call the remote_api in principle.

Therefore, I started to study this problem. First, I used the simplest method to specify the data to access that app through the parameter _ app:

 

Class Remotedata3page (webapp. requesthandler ):
  Def Get (Self ):
Self. response. Out. Write ( " Fetch remote data only use _ app Param: " )
Places = DB. gqlquery (( " Select * From pla_names where parentcode = '0' " ), * {}, ** { ' _ App ' : ' Dituren-Service ' }). Fetch ( 100 )
For Place In Places:
Self. response. Out. Write (place. Name + " , " )

 

The following parameter _ app specifies which app to access the data under. After using this parameter, I found that the returned data is blank during local development and debugging, because the app named dituren-service was not found locally, When I uploaded the app to the server for running, the error 500 occurred. When I went to the backend, I checked that the error was as follows:
"Adrequesterror: app dituren-WWW cannot access app dituren-Service's data"
It indicates that Google does not allow cross-app access to data in a policy. Of course, I did not expect direct access because there is no such thing in the Google documentation.

Since direct access is not allowed, we should temporarily use remote_api to find the method of using remote_api from the Google documentation and access data using this method:

 

Def Auth_func ():
Return   " Myusername@gmail.com " , " Mypassword "

Class Remotedata1page (webapp. requesthandler ):
  Def Get (Self ):
Self. response. Out. Write ( " Fetch remote data use 'Google. appengine. Ext. remote_api ': " )
Remote_api_stub = _ Import __ ( ' Google. appengine. Ext. remote_api.remote_api_stub ' ). Appengine. Ext. remote_api.remote_api_stub
Remote_api_stub.configureremotedatastore ( " Dituren-Service " , ' /Data/remote_api ' , Auth_func, " Dituren-service.appspot.com " )
Places = DB. gqlquery (( " Select * From pla_names where parentcode = '0' " ), * {}, ** { ' _ App ' : ' Dituren-Service ' }). Fetch ( 100 )
For Place In Places:
Self. response. Out. Write (place. Name + " , " )

 

Run it locally to display the results. If it is not OK, It will be strange because it is used according to the Google documentation, but it is still 500 error when uploading the file, go to the background and check it:
"No module named Tools"
It seems that the remote_api ClientCodeIt is specially developed for the SDK and can be connected only when the SDK is installed. The Gae appspot server does not have any necessary content, so it cannot run.
This makes me very confused, because the Gae server currently only supports HTTP connections, so the remote_api server is actually implemented through HTTP, however, Gae development can access HTTP interfaces. Why cannot I access remote_api?
So I thought that I could copy the remote_api_stub code and change it. Maybe it could be implemented. So I copied the relevant file to the remote_api of the app, changed the code several times, and then uploaded it for a look, run the following code:

 

Class Remotedata2page (webapp. requesthandler ):
  Def Get (Self ):
Self. response. Out. Write ( " Fetch remote data use local remote_api: " )
Remote_api_stub = _ Import __ ( ' Remote_api.remote_api_stub ' ). Remote_api_stub
Remote_api_stub.configureremotedatastore ( " Dituren-Service " , ' /Data/remote_api ' , Auth_func, " Dituren-service.appspot.com " )
Places = DB. gqlquery (( " Select * From pla_names where parentcode = '0' " ), * {}, ** { ' _ App ' : ' Dituren-Service ' }). Fetch ( 100 )
For Place In Places:
Self. response. Out. Write (place. Name + " , " )

 

Eventually, it still fails. My debugging process is as follows:
1. First, copy google_appengine \ google \ appengine \ ext \ remote_api \ remote_api_stub.py to the remote_api folder in the app root directory, and check whether "No module named Tools" is the same as the preceding error;
2. copy google_appengine \ google \ appengine \ tools \ appengine_rpc.py to the remote_api folder in the app root directory, change the call in remote_api_stub.py, and display "module object has no attribute getdefatimetimeout ", this makes me confused, because the Gae document shows that urllib and socket can be used. Why do I just move the corresponding code to my app directory, what happens when the method of the connected class does not exist ?;
3. I want to delete the place where the socket is used in appengine_rpc, because it does not seem very important to me, but after the deletion, the content downloaded from the server is blank, that is, I do not know what is going on;
4. I changed the HTTP access code in appengine_rpc to urlfetch, which can also be run. However, urlfetch cannot specify a cookie, but to access remote_api, you must use a cookie, therefore, 302 status codes are always obtained each time;
5. I want to disable the user authentication of remote_api. I think it is okay to access the app without using cookies. after removing login: Admin from yaml, the server returns a text saying that this service can only be used by the logged-on administrator. In fact, the "login: admin "is redundant ......

After the above ups and downs, I no longer have patience, So I declared a failure. If anyone knows how to easily share data between apps, I will not study this for the time being.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.