GAE Remote API - Cannot connect

泄露秘密 提交于 2019-12-24 14:31:42

问题


Ok, I'm attempting unsuccessfully to connect to a remote datastore and populate from my local machine using the steps outlined here: https://cloud.google.com/appengine/docs/java/tools/remoteapi#Configuring_Remote_API_on_the_Client

public static void main(String[] args) {

    String username = "myemail@gmail.com";
    String password = "mygmailpassword";
    RemoteApiOptions options = new RemoteApiOptions()
        .server("myappname.appspot.com", 443)
        .credentials(username, password);
    RemoteApiInstaller installer = new RemoteApiInstaller();
    installer.install(options);

    try {       
        DatastoreService ds = DatastoreServiceFactory.getDatastoreService();
        ...

I'm getting a 404 in installer.install(options): java.io.IOException: can't get appId from remote api; status code = 404 Am I missing something here? I enabled the remote api in my web.xml and deployed to GAE. I am the owner of the project.


回答1:


Run your service locally (with remote api enabled) and try running same code using 'localhost' and 8888 (port) and check if your code can access locally running service. Your code seems right. There are 2 possibilities - 1. RemoteApi is not enabled correctly. 2. app-name is not spelled correctly.

Other than this, I also use following code to access remote api-

        installer.install(options);
        try {
            // Update the options with reusable credentials so we can skip
            // authentication on subsequent calls.
            options.reuseCredentials(username, installer.serializeCredentials());
        } finally {
            installer.uninstall();
        }

However, that shouldn't give you the error you're getting.




回答2:


I realize this is coming a bit late, but I just found this when googling because I had a similar problem, and I solved it for myself. For me the problem was, that my AppEngine app that was serving the remote API, was a python app, and the python docs instruct configuring the remote api endpoint as /remoteapi.*

However my remote api client is a java application, and apparently the remote api call it makes, goes to an endpoit like this: /remote_api. So adding that to the server route configuration (in my case app.yaml) solved the problem. Please note also, that if your remote api serving appengine app is not in the default module, the url should be something like my-module-name-dot-my-project.appspot.com

Also, you should use useApplicationDefaultCredential() instead of credentials(), it is deprecated.



来源:https://stackoverflow.com/questions/27769581/gae-remote-api-cannot-connect

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!