Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

It seems *api_server* is misconfigured. #98

Closed
Zeko403 opened this issue Jan 29, 2020 · 22 comments
Closed

It seems *api_server* is misconfigured. #98

Zeko403 opened this issue Jan 29, 2020 · 22 comments

Comments

@Zeko403
Copy link

Zeko403 commented Jan 29, 2020

After setting up trains Docker image together with trains package in my local library, I keep getting issues when I'm trying to connect to trains api server.

Specifically, after running
docker-compose

The following error message can be found in the console:
trains-apiserver | raise ConnectionError(e, request=request) trains-apiserver | requests.exceptions.ConnectionError: HTTPSConnectionPool(host='updates.trains.allegro.ai', port=443): Max retries exceeded with url: /updates (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7f390d528da0>: Failed to establish a new connection: [Errno -2] Name or service not known',))

When I try to import Task from trains, no error until I run this:

task = Task.init(project_name="my project", task_name="my task")

Resulting in the following error message:

`InsecureRequestWarning: Certificate verification is disabled! Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
Traceback (most recent call last):
File "C:\ProgramData\Miniconda3\envs\jurica\lib\site-packages\trains\backend_api\session\session.py", line 545, in _do_refresh_token
return resp["data"]["token"]
KeyError: 'data'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "", line 1, in
File "C:\ProgramData\Miniconda3\envs\jurica\lib\site-packages\trains\task.py", line 260, in init
reuse_last_task_id,
File "C:\ProgramData\Miniconda3\envs\jurica\lib\site-packages\trains\task.py", line 1009, in _create_dev_task
log_to_backend=True,
File "C:\ProgramData\Miniconda3\envs\jurica\lib\site-packages\trains\task.py", line 112, in init
super(Task, self).init(**kwargs)
File "C:\ProgramData\Miniconda3\envs\jurica\lib\site-packages\trains\backend_interface\task\task.py", line 81, in init
super(Task, self).init(id=task_id, session=session, log=log)
File "C:\ProgramData\Miniconda3\envs\jurica\lib\site-packages\trains\backend_interface\base.py", line 129, in init
super(IdObjectBase, self).init(session, log, **kwargs)
File "C:\ProgramData\Miniconda3\envs\jurica\lib\site-packages\trains\backend_interface\base.py", line 34, in init
self._session = session or self._get_default_session()
File "C:\ProgramData\Miniconda3\envs\jurica\lib\site-packages\trains\backend_interface\base.py", line 103, in _get_default_session
secret_key=ENV_SECRET_KEY.get(),
File "C:\ProgramData\Miniconda3\envs\jurica\lib\site-packages\trains\backend_api\session\session.py", line 144, in init
self.refresh_token()
File "C:\ProgramData\Miniconda3\envs\jurica\lib\site-packages\trains\backend_api\session\token_manager.py", line 95, in refresh_token
self._set_token(self._do_refresh_token(self.__token, exp=self.req_token_expiration_sec))
File "C:\ProgramData\Miniconda3\envs\jurica\lib\site-packages\trains\backend_api\session\session.py", line 552, in _do_refresh_token
'Is this the TRAINS API server {} ?'.format(self.get_api_server_host()))
ValueError: It seems api_server is misconfigured. Is this the TRAINS API server http://localhost:8008 ?`

I have set up the trains.conf file to contain the following:

`# TRAINS SDK configuration file
api {
# API server on port 8008
api_server: "http://localhost:8008"

  # web_server on port 8080
  web_server: "http://localhost:8080"

  # file server on port 8081
  files_server: "http://localhost:8081"
  verify_certificate: False

}`

As I am behind a corporate proxy, I set that up and that should be working fine.
Is the issue on my side, maybe due to DNS or is there another explanation?
Much appreciated!

@bmartinn
Copy link
Member

Hi @Zeko403,

Can you verify trains-server has been successfully started? The easiest way to do that is to open your browser, go to the trains-webserver url (in your case, http://localhost:8080), and make sure you can log in and that no errors are shown.

@Zeko403
Copy link
Author

Zeko403 commented Jan 30, 2020

The webserver works fine by the looks of it, I can access it and type my username there, also I can access http://localhost:8080/profile

Edit: Output from the console:
trains-webserver | 172.18.0.1 - - [30/Jan/2020:10:42:59 +0000] "GET /profile HTTP/1.1" 200 680 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36 OPR/66.0.3515.44" "-" trains-webserver | 172.18.0.1 - - [30/Jan/2020:10:43:02 +0000] "GET /app/webapp-common/assets/icons/plus-blue.svg HTTP/1.1" 200 184 "http://localhost:8080/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36 OPR/66.0.3515.44" "-" trains-webserver | 172.18.0.1 - - [30/Jan/2020:10:43:02 +0000] "GET /fa-solid-900.b5cf8ae26748570d8fb9.woff2 HTTP/1.1" 200 75440 "http://localhost:8080/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36 OPR/66.0.3515.44" "-" trains-webserver | 172.18.0.1 - - [30/Jan/2020:10:43:02 +0000] "GET /Heebo-Medium.6c57263dbdee325394e4.ttf HTTP/1.1" 200 58552 "http://localhost:8080/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36 OPR/66.0.3515.44" "-"

@bmartinn
Copy link
Member

Hi @Zeko403
This looks like something is off with the configuration (because the browser seems to be able to aceess both the web server and the api server)

Could you delete the ~/trains.conf configuration file and execute the trains configuration wizard?

$ trains init

It should not only configure the all the servers, but it will also try to validate your credentials with the trains-server.

Let me know if it helped.

@Zeko403
Copy link
Author

Zeko403 commented Feb 4, 2020

Hi @bmartinn

OK so I tried deleting the trains.conf file (I'm on Windows so the trains.conf file was in C:\Users\Name\trains.conf). Then I ran the trains-init which resulted in following

This was the last line of trains-apiserver after starting the docker:
trains-apiserver |
trains-apiserver | During handling of the above exception, another exception occurred:
trains-apiserver |
trains-apiserver | Traceback (most recent call last):
trains-apiserver | File "/opt/trains/server/updates.py", line 96, in _check_updates
trains-apiserver | response = self._check_new_version_available()
trains-apiserver | File "/opt/trains/server/updates.py", line 54, in _check_new_version_available
trains-apiserver | config.get("apiserver.check_for_updates.request_timeout_sec", 3.0)
trains-apiserver | File "/usr/local/lib/python3.6/site-packages/requests/api.py", line 75, in get
trains-apiserver | return request('get', url, params=params, **kwargs)
trains-apiserver | File "/usr/local/lib/python3.6/site-packages/requests/api.py", line 60, in request
trains-apiserver | return session.request(method=method, url=url, **kwargs)
trains-apiserver | File "/usr/local/lib/python3.6/site-packages/requests/sessions.py", line 533, in request
trains-apiserver | resp = self.send(prep, **send_kwargs)
trains-apiserver | File "/usr/local/lib/python3.6/site-packages/requests/sessions.py", line 646, in send
trains-apiserver | r = adapter.send(request, **kwargs)
trains-apiserver | File "/usr/local/lib/python3.6/site-packages/requests/adapters.py", line 516, in send
trains-apiserver | raise ConnectionError(e, request=request)
trains-apiserver | requests.exceptions.ConnectionError: HTTPSConnectionPool(host='updates.trains.allegro.ai', port=443): Max retries exceeded with url: /updates (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7f2f0dbce128>: Failed to establish a new connection: [Errno -2] Name or service not known',))

Then after I ran the trains-init showing that it actually is responsive:
trains-apiserver | [2020-02-04 09:38:53,043] [8] [INFO] [trains.service_repo] Returned 200 for users.get_preferences in 5ms
trains-apiserver | [2020-02-04 09:38:53,116] [8] [INFO] [trains.service_repo] Returned 200 for users.get_current_user in 6ms
trains-apiserver | [2020-02-04 09:38:53,122] [8] [INFO] [trains.service_repo] Returned 200 for projects.get_all_ex in 9ms
trains-apiserver | [2020-02-04 09:38:53,123] [8] [INFO] [trains.service_repo] Returned 200 for auth.get_credentials in 2ms
trains-apiserver | [2020-02-04 09:38:53,214] [8] [INFO] [trains.service_repo] Returned 200 for server.report_stats_option in 1ms
trains-apiserver | [2020-02-04 09:38:54,999] [8] [INFO] [trains.service_repo] Returned 200 for auth.create_credentials in 7ms`

After I pasted the code from the generated access key:
`api {
web_server: http://localhost:8080
api_server: http://localhost:8008
credentials {
"access_key" = "GF3TDJGA2PXZPYHU1DN1"
"secret_key" = "0LZeLYtm8#3p!SeigF=Jr6+JYD6hJUXrSqy^oZSt+uLmna9Ydf"
}
}
I got this in the console:

TRAINS SDK setup process

Please create new trains credentials through the profile page in your trains web app (e.g. http://localhost:8080/profile)
In the profile page, press "Create new credentials", then press "Copy to clipboard".

Paste copied configuration here:
api {
web_server: http://localhost:8080
api_server: http://localhost:8008
credentials {
"access_key" = "GF3TDJGA2PXZPYHU1DN1"
"secret_key" = "0LZeLYtm8#3p!SeigF=Jr6+JYD6hJUXrSqy^oZSt+uLmna9Ydf"
}
}
Detected credentials key="GF3TDJGA2PXZPYHU1DN1" secret="0LZe***"
API Host configured to: [http://localhost:8008]
Port 8008 is the api port. Replacing 8080 with 8008 for Web application
Web Application Host configured to: [http://localhost:8080]
File Store Host configured to: [http://localhost:8081]

TRAINS Hosts configuration:
Web App: http://localhost:8080
API: http://localhost:8008
File Store: http://localhost:8081

Verifying credentials ...
Exception: It seems api_server is misconfigured. Is this the TRAINS API server https://demoapi.trains.allegro.ai ?
Error: could not verify credentials: key=GF3TDJGA2PXZPYHU1DN1 secret=0LZeLYtm8#3p!SeigF=Jr6+JYD6hJUXrSqy^oZSt+uLmna9Ydf
Enter user access key:

After which I put the same key and secret in and got the same error api_server is misconfigured.

It seems there is some communication error but I cannot put my finger on it...

@bmartinn
Copy link
Member

Hi @Zeko403 , my apologies for the delay, this thread somehow slipped away from me.

It seems there is a bug in the message print, it printed the default "https://demoapi.trains.allegro.ai" instead of the localhost:8008 (which will be promptly fixed in the next RC),

But the real question is why the credentials failed to verify with the API server onhttp://localhost:8008

This is actually consistent with the original post where it crashed with:

line 545, in _do_refresh_token
return resp["data"]["token"]
KeyError: 'data'

The reason the trains-init is suggesting it might be that the "api_server is misconfigured." is because the "data" field is missing on the returned request from the API server.

I suspect it might be the mongo docker. Could you verify that all docker services are working correctly ? Please execute:
$ docker ps

It should list all 6 containers with equal uptime (If one is misbehaving, it will either not be listed or uptime will be a few seconds since it will constantly restart):

CONTAINER ID        IMAGE                                                  COMMAND                  CREATED             STATUS              PORTS                                           NAMES
2d7820ab0fd3        allegroai/trains:latest                                "/opt/trains/wrapper…"   6 weeks ago         Up 17 minutes       8008/tcp, 8080-8081/tcp, 0.0.0.0:8080->80/tcp   trains-webserver
9fc6acc64930        allegroai/trains:latest                                "/opt/trains/wrapper…"   6 weeks ago         Up 17 minutes       0.0.0.0:8008->8008/tcp, 8080-8081/tcp           trains-apiserver
8d944ba0ac80        redis:5.0                                              "docker-entrypoint.s…"   6 weeks ago         Up 17 minutes       0.0.0.0:6379->6379/tcp                          trains-redis
b6af7111e3eb        allegroai/trains:latest                                "/opt/trains/wrapper…"   6 weeks ago         Up 17 minutes       8008/tcp, 8080/tcp, 0.0.0.0:8081->8081/tcp      trains-fileserver
4f9b7db06115        docker.elastic.co/elasticsearch/elasticsearch:5.6.16   "/bin/bash bin/es-do…"   2 months ago        Up 17 minutes       0.0.0.0:9200->9200/tcp, 9300/tcp                trains-elastic
3ed89332e232        mongo:3.6.5                                            "docker-entrypoint.s…"   2 months ago        Up 17 minutes       0.0.0.0:27017->27017/tcp                        trains-mongo

@Zeko403
Copy link
Author

Zeko403 commented Feb 17, 2020

Hi again @bmartinn thanks for helping out

The output i get is pretty similar to what you expected:

$ docker ps
CONTAINER ID        IMAGE                                                  COMMAND                  CREATED             STATUS              PORTS                                           NAMES
0dac9c9577d4        allegroai/trains:latest                                "/opt/trains/wrapper…"   13 days ago         Up 34 seconds       8008/tcp, 8080-8081/tcp, 0.0.0.0:8080->80/tcp   trains-webserver
cd7084d0a728        allegroai/trains:latest                                "/opt/trains/wrapper…"   13 days ago         Up 35 seconds       0.0.0.0:8008->8008/tcp, 8080-8081/tcp           trains-apiserver
4ef8fd7195f3        docker.elastic.co/elasticsearch/elasticsearch:5.6.16   "/bin/bash bin/es-do…"   13 days ago         Up 35 seconds       0.0.0.0:9200->9200/tcp, 9300/tcp                trains-elastic
ba92219c5993        allegroai/trains:latest                                "/opt/trains/wrapper…"   13 days ago         Up 35 seconds       8008/tcp, 8080/tcp, 0.0.0.0:8081->8081/tcp      trains-fileserver
580b2c5d6e35        redis:5.0                                              "docker-entrypoint.s…"   13 days ago         Up 35 seconds       0.0.0.0:6379->6379/tcp                          trains-redis
e7da6389deae        mongo:3.6.5                                            "docker-entrypoint.s…"   13 days ago         Up 35 seconds       0.0.0.0:27017->27017/tcp                        trains-mongo

@bmartinn
Copy link
Member

Hi @Zeko403,

This is very strange... It seems the mongodb container is up and running...
Can you please try entering the following cURL commands and sharing their output?

$ curl http://localhost:8008/server.info
$ curl -u GF3TDJGA2PXZPYHU1DN1:0LZeLYtm8#3p\!SeigF=Jr6+JYD6hJUXrSqy^oZSt+uLmna9Ydf http://localhost:8008/auth.login

The first call should simply display the server version and build, while the second one attempts to obtain a token based on the user credentials you shared in a previous post on this thread.

@Zeko403
Copy link
Author

Zeko403 commented Feb 24, 2020

EDIT:
I edited the post as I was running the cmd.exe with elevated rights that did not bypass the proxy setting.

To answer your questions :

curl http://localhost:8008/server.info
{"meta":{"id":"765ddb82e88d4a8f80639cf2aeb36dfb","trx":"765ddb82e88d4a8f80639cf2aeb36dfb","endpoint":{"name":"server.info","requested_version":"2.6","actual_version":"1.0"},"result_code":200,"result_subcode":0,"result_msg":"OK","error_stack":""},"data":{"version":"0.13.0","build":"262","commit":""}}

and

curl -u GF3TDJGA2PXZPYHU1DN1:0LZeLYtm8#3p\!SeigF=Jr6+JYD6hJUXrSqy^oZSt+uLmna9Ydf http://localhost:8008/auth.login
{"meta":{"id":"f379cc599fc245988dc585b26706e387","trx":"f379cc599fc245988dc585b26706e387","endpoint":{"name":"auth.login","requested_version":"2.6","actual_version":"1.0"},"result_code":401,"result_subcode":22,"result_msg":"Unauthorized (invalid credentials) (failed to locate provided credentials)","error_stack":null},"data":{}}

Disregard the comment below, I figured out that I ran the cmd.exe with admin rights and then it did not ignore the proxy rules:


Hi @bmartinn and thanks for still helping out.

I tried calling curl for both links but I get no response whatsoever, then I updated curl to the newest version, still the same.
For curl.exe http://google.com I get

<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>301 Moved</TITLE></HEAD><BODY>
<H1>301 Moved</H1>
The document has moved
<A HREF="http://www.google.com/">here</A>.
</BODY></HTML>

So I tried adding "-v" in addition

curl.exe http://google.com -v
* Uses proxy env variable http_proxy == "my_proxy_link"
*   Trying 10.116.253.73:80...
* Connected to "my_proxy_link" (my_proxy_ip) port of_my_proxy (#0)
> GET http://google.com/ HTTP/1.1
> Host: google.com
> User-Agent: curl/7.69.0-DEV
> Accept: */*
> Proxy-Connection: Keep-Alive
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 301 Moved Permanently
< Location: http://www.google.com/
< Content-Type: text/html; charset=UTF-8
< Date: Mon, 24 Feb 2020 08:33:18 GMT
< Expires: Wed, 25 Mar 2020 08:33:18 GMT
< Cache-Control: public, max-age=2592000
< Server: gws
< Content-Length: 219
< X-XSS-Protection: 0
< X-Frame-Options: SAMEORIGIN
<
<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>301 Moved</TITLE></HEAD><BODY>
<H1>301 Moved</H1>
The document has moved
<A HREF="http://www.google.com/">here</A>.
</BODY></HTML>
* Connection #0 to host "my_proxy_link" left intact

So I am not sure if there is something wrong because I am using a proxy, I did set up the proxy in the docker as described.

Interestingly, when I just try to look up http://localhost:8008/server.info in my browser
I get this :

{"meta":{"id":"32a9a6aab76d42218af7e597d53cac88","trx":"32a9a6aab76d42218af7e597d53cac88","endpoint":{"name":"server.info","requested_version":"2.6","actual_version":"1.0"},"result_code":200,"result_subcode":0,"result_msg":"OK","error_stack":""},"data":{"version":"0.13.0","build":"262","commit":""}}

@bmartinn
Copy link
Member

bmartinn commented Feb 25, 2020

Hi @Zeko403 , I think you just pointed to the problem, the proxy server configuration is not picked unless you are running with Admin privileges.

Could you run the python script with elevated Admin privilege? (You can start an elevated Admin cmd.exe shell, and execute the python script there)

p.s.
I think that what you are saying is that Admin rights are a must to get it to work, but it could be the other way around...

@Zeko403
Copy link
Author

Zeko403 commented Feb 25, 2020

Hi @bmartinn

I tried running Docker, cmd docker-compose -f docker-compose-win10.yml up and cmd curl http://localhost:8008/server.info with Admin rights ending up with the same result as above.

in addition, running trains-init also with admin rights gives the same error as before the Exception: It seems *api_server* is misconfigured. Is this the TRAINS API server https://demoapi.trains.allegro.ai ?

Nowhere have I configured the TRAINS API server to point to https://demoapi.trains.allegro.ai, so I don't know where this link is coming from.

I get the feeling that server api keeps looking at the https://demoapi.trains.allegro.ai instead of localhost:8080 to communicate with the webserver even when I am using the trains-init command.

I generated a new key on webserver and then called trains-init and got the following messages:

trains-init
TRAINS SDK setup process

Please create new trains credentials through the profile page in your trains web app (e.g. http://localhost:8080/profile)
In the profile page, press "Create new credentials", then press "Copy to clipboard".

Paste copied configuration here:
api {
    web_server: http://localhost:8080
    api_server: http://localhost:8008
    credentials {
        "access_key" = "ABAVVQVDZYH4TIEQS0J5"
        "secret_key" = "hR!9iSgffacQ3BLY+pTl@kZo8fzA63JwGqwaEWUgt3jB1pIbfw"
    }
}
Detected credentials key="ABAVVQVDZYH4TIEQS0J5" secret="hR!9***"
API Host configured to: [http://localhost:8008]
Port 8008 is the api port. Replacing 8080 with 8008 for Web application
Web Application Host configured to: [http://localhost:8080]
File Store Host configured to: [http://localhost:8081]

TRAINS Hosts configuration:
Web App: http://localhost:8080
API: http://localhost:8008
File Store: http://localhost:8081

Verifying credentials ...
Exception: It seems *api_server* is misconfigured. Is this the TRAINS API server https://demoapi.trains.allegro.ai ?
Error: could not verify credentials: key=ABAVVQVDZYH4TIEQS0J5 secret=hR!9iSgffacQ3BLY+pTl@kZo8fzA63JwGqwaEWUgt3jB1pIbfw
Enter user access key:

Why is there a message Port 8008 is the api port. Replacing 8080 with 8008 for Web application if I added the web_server: http://localhost:8080 and api_server: http://localhost:8008 ?

@bmartinn
Copy link
Member

I get the feeling that server api keeps looking at the https://demoapi.trains.allegro.ai instead of localhost:8080 to communicate with the webserver even when I am using the trains-init command.
and
Why is there a message Port 8008 is the api port. Replacing 8080 with 8008 for Web application if I added the web_server: http://localhost:8080 and api_server: http://localhost:8008 ?

Apologies @Zeko403 , this was a bug with the information printed in trains-init (just the print, not the actual values). It is fixed in the latest trains package, you can upgrade with:
pip install trains==0.13.3

Here is a recap of what I understand so far:

  1. Host OS Windows 10
  2. trains-server running on the Host Windows 10 machine with Docker App
  3. Windows browser can access "http://localhost:8080" (the TRAINS web app)
  4. Windows browser can access "http://localhost:8008" (the TRAINS api server)
  5. Running shell cmd.exe with user credentials cannot access the api server
  6. Running shell cmd.exe with Admin credentials can access the api server

Is the above correct?

@Zeko403
Copy link
Author

Zeko403 commented Feb 25, 2020

Here is a recap of what I understand so far:

  1. Host OS Windows 10
  2. trains-server running on the Host Windows 10 machine with Docker App
  3. Windows browser can access "http://localhost:8080" (the TRAINS web app)
  4. Windows browser can access "http://localhost:8008" (the TRAINS api server)
  5. Running shell cmd.exe with user credentials cannot access the api server
  6. Running shell cmd.exe with Admin credentials can access the api server

Is the above correct?

  1. Correct,
  2. Correct,
  3. Correct, I use that to generate and add users credentials
  4. Yes, but in the browser for only http://localhost:8008/ I get
    {"meta":{"id":"100f122cce19428c80762296f6d93f77","trx":"100f122cce19428c80762296f6d93f77","endpoint":{"name":"","requested_version":1.0,"actual_version":null},"result_code":400,"result_subcode":0,"result_msg":"Invalid request path /","error_stack":null},"data":{}}
    and when I use http://localhost:8008/server.info I get
    {"meta":{"id":"631ffc54e9aa47ad874d728b8042391c","trx":"631ffc54e9aa47ad874d728b8042391c","endpoint":{"name":"server.info","requested_version":"2.6","actual_version":"1.0"},"result_code":200,"result_subcode":0,"result_msg":"OK","error_stack":""},"data":{"version":"0.13.0","build":"262","commit":""}}

When I call curl http://localhost:8008/server.info as you mention in 5. and 6. with and without admin rights I get the same as in the browser(s)
{"meta":{"id":"70fb185bf1d54d27aa200204b20b4137","trx":"70fb185bf1d54d27aa200204b20b4137","endpoint":{"name":"server.info","requested_version":"2.6","actual_version":"1.0"},"result_code":200,"result_subcode":0,"result_msg":"OK","error_stack":""},"data":{"version":"0.13.0","build":"262","commit":""}} C:\WINDOWS\system32>

I will try updating trains and report if there are any changes

EDIT:
After updating the trains, generated new credentials and no I get

TRAINS SDK setup process

Please create new trains credentials through the profile page in your trains web app (e.g. http://localhost:8080/profile)
In the profile page, press "Create new credentials", then press "Copy to clipboard".

Paste copied configuration here:
api {
    web_server: http://localhost:8080
    api_server: http://localhost:8008
    credentials {
        "access_key" = "6N8PY3DKU8656LHIDRPF"
        "secret_key" = "YiAZW(nIF1L#$dqwF8PlFMX0R07A@$x-@LeLT=(MVtc5sGYdFR"
    }
}
Detected credentials key="6N8PY3DKU8656LHIDRPF" secret="YiAZ***"
API Host configured to: [http://localhost:8008]
Web Application Host configured to: [http://localhost:8080]
File Store Host configured to: [http://localhost:8081]

TRAINS Hosts configuration:
Web App: http://localhost:8080
API: http://localhost:8008
File Store: http://localhost:8081

Verifying credentials ...
Exception: It seems *api_server* is misconfigured. Is this the TRAINS API server http://localhost:8008 ?
Error: could not verify credentials: key=6N8PY3DKU8656LHIDRPF secret=YiAZW(nIF1L#$dqwF8PlFMX0R07A@$x-@LeLT=(MVtc5sGYdFR

@bmartinn
Copy link
Member

I suspect this is the proxy forwarding ...
Could you please run the following python code and post the result:

import requests
requests.get('http://localhost:8008/server.info').text

@Zeko403
Copy link
Author

Zeko403 commented Feb 25, 2020

it seems you are most likely right, the output is pretty long, but it is a response from the proxy server saying that the request is blocked due to invalid server IP.
I got in touch with our IT service regarding this issue, so we set up the system environment variable (NO_PROXY = localhost) to not go via proxy for localhost. The same is configured in the Docker settings and manual proxy settings are set up too.

@bmartinn
Copy link
Member

hmmm, accessing localhost should not go through the proxy, this is why it took so long to debug ...
Out of curiosity , what happens when you execute:

import requests
requests.get('http://127.0.0.1:8008/server.info').text

@Zeko403
Copy link
Author

Zeko403 commented Feb 25, 2020

I agree it shouldn't, especially after both browser and curl can access the same link.
The response for 127.0.0.1:8008/server.info is the same as for the localhost

Maybe it is a problem with the requests package? It somehow bypasses the NO_PROXY settings set up in the system environment maybe?

EDIT

I tried the following code

import requests
session = requests.Session()
session.trust_env = False
session.get('http://127.0.0.1:8008/server.info').text

To which I got the expected result:

{"meta":{"id":"b757ecf3fbe542f9aa1e8988a3886503","trx":"b757ecf3fbe542f9aa1e8988a3886503","endpoint":{"name":"server.info","requested_version":"2.6","actual_version":"1.0"},"result_code":200,"result_subcode":0,"result_msg":"OK","error_stack":""},"data":{"version":"0.13.0","build":"262","commit":""}}

@bmartinn
Copy link
Member

bmartinn commented Feb 25, 2020

Hurray!! 🎊
I guess the localhost was resolved by your system, and hence the proxy settings were added, while 127.0.0.1 is a direct loopback IP , so by definition, no proxy.

Okay, so all you need to do is configure trains with :

api {
    web_server: http://127.0.0.1:8080
    api_server: http://127.0.0.1:8008
    files_server: http://127.0.0.1:8081
    credentials {
        "access_key" = "ABAVVQVDZYH4TIEQS0J5"
        "secret_key" = "hR!9iSgffacQ3BLY+pTl@kZo8fzA63JwGqwaEWUgt3jB1pIbfw"
    }
}

EDIT
I just noticed you had to add session.trust_env = False.
Could you test the following:

import os
os.environ['no_proxy'] = '*' 
os.environ['NO_PROXY'] = '*' 
import requests
requests.get('http://127.0.0.1:8008/server.info').text

@Zeko403
Copy link
Author

Zeko403 commented Feb 25, 2020

Yes, only with the added line you mentioned it worked.

Regarding your test request this is the following output (a good one :))

>>> import os
>>> os.environ['no_proxy'] = '*'
>>> os.environ['NO_PROXY'] = '*'
>>> import requests
>>> requests.get('http://127.0.0.1:8008/server.info').text
'{"meta":{"id":"b6e93a900b6149a1b0c8d84fd30f419d","trx":"b6e93a900b6149a1b0c8d84fd30f419d","endpoint":{"name":"server.info","requested_version":"2.6","actual_version":"1.0"},"result_code":200,"result_subcode":0,"result_msg":"OK","error_stack":""},"data":{"version":"0.13.0","build":"262","commit":""}}'

Another weird thing is that the localhost:8080/profile has different users than the 127.0.0.1:8080/profile, but both result with the same error after pasting the generated generator file after invoking trains-init in the console.

@bmartinn
Copy link
Member

bmartinn commented Feb 25, 2020

Okay we might have a solution:

  • In your shell cmd.exe set the following set no_proxy=127.0.0.1 && set NO_PROXY=127.0.0.1
  • Open your browser http://127.0.0.1:8080 and create new credentials
  • Execute trains-init from the same shell, and set it with the newly generated credentials:
api {
    web_server: http://127.0.0.1:8080
    api_server: http://127.0.0.1:8008
    files_server: http://127.0.0.1:8081
    credentials {
        "access_key" = 
        "secret_key" = 
    }
}

🤞

EDIT
Before everything please verify this one works:

import os
os.environ['no_proxy'] = '127.0.0.1' 
os.environ['NO_PROXY'] = '127.0.0.1' 
import requests
requests.get('http://127.0.0.1:8008/server.info').text

@Zeko403
Copy link
Author

Zeko403 commented Feb 25, 2020

Dude @bmartinn that worked!

Got the response now:

`Verifying credentials ...
Credentials verified!

New configuration stored in C:\Users\engineer\trains.conf
TRAINS setup completed successfully.`

I will now try the trains-agent and see if I can get it up and running
Thank you very much for all your help so far!

@bmartinn
Copy link
Member

🚀 Awesome !!!

@Zeko403
Copy link
Author

Zeko403 commented Feb 26, 2020

Just to confirm, everything is up and running now after some extensive testing.

In your shell cmd.exe set the following set no_proxy=127.0.0.1 && set NO_PROXY=127.0.0.1

has enabled normal communication between all the servers. Thanks again for all your help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants