mathworks / matlab-proxy

Python® package enables you to open a MATLAB® desktop in a web browser tab.
Other
47 stars 23 forks source link

Failed to authenticate by Online License Manager under http proxy environment #31

Closed utotch closed 7 months ago

utotch commented 7 months ago

Summary

As I reported here, I failed to authenticate my license by Online License Manager under http proxy environment.

I believe I input my correct Email and password because the manager responded, "Invalid Email or Password" for the wrong password but answered that it doesn't proceed for the correct password, which looked like it recognized the password.

[My observation] I'm afraid the implementation of the matlab-proxy with aiohttp doesn't process HTTP_PROXY info properly.

This document shows how to introduce proxy support by using aiohttp: https://docs.aiohttp.org/en/stable/client_advanced.html

This says,

Contrary to the requests library, it won’t read environment variables by default. But you can do so by passing trust_env=True into aiohttp.ClientSession constructor.:

async with aiohttp.ClientSession(trust_env=True) as session:
    async with session.get("http://python.org") as resp:
        print(resp.status)

by default, aiohttp ignores PROXY related environment variables.

according from mw.py code (line102-):

    async with aiohttp.ClientSession() as client_session:
        async with client_session.post(
            f"{mwa_api_endpoint}/tokens",
            headers={
                "content-type": "application/x-www-form-urlencoded",
                "accept": "application/json",
                "X_MW_WS_callerId": "desktop-jupyter",
            },
            data=aiohttp.FormData(
                {
                    "tokenString": identity_token,
                    "tokenPolicyName": "R2",
                    "sourceId": source_id,
                }
            ),

Client session is initialized without passing any arguments.

I'm afraid this code should be:

async with aiohttp.ClientSession(trust_env=True) as client_session:

that changes aiohttp to read proxy related environment variables.

-- my environment: ubuntu linux 20 or 22 with Docker

Browser(s) used

Chrome

Script output

No response

prabhakk-mw commented 7 months ago

Hi @utotch

Thank you for pursuing this.

Would it be possible for you to share the values of the environment variables:

Also, could you re-try by ensuring that :

are present in the no_proxy & NO_PROXY values ?

Thanks

utotch commented 7 months ago

Hi, @prabhakk-mw

Thanks for the reply. I just tried with setting the above no_proxy values, but nothing improved.

In my observation, we can't solve this problem just by changing proxy-related environment variables.

I show my setting partly (sorry for hiding some part for privacy and security reason): I tried below:

docker run -it --rm \
  --shm-size=512M \
  -p 8897:8888 \
  -e http_proxy=http://10.81.XXX.XX:8080 \
  -e HTTP_PROXY=http://10.81.XXX.XX4:8080 \
  -e https_proxy=http://10.81.XXX.XX:8080 \
  -e HTTPS_PROXY=http://10.81.XXX.XX:8080 \
  -e no_proxy=".mathworks.com,localhost,127.0.0.1" \
  -e NO_PROXY=".mathworks.com,localhost,127.0.0.1" \
  mathworks/matlab:r2023b -browser

And I believe the environment values are properly set.

$ env | grep -i proxy
no_proxy=.mathworks.com,localhost,127.0.0.1
https_proxy=http://10.81.XXX.XX:8080
NO_PROXY=.mathworks.com,localhost,127.0.0.1
HTTPS_PROXY=http://10.81.XXX.XX:8080
HTTP_PROXY=http://10.81.XXX.XX:8080
http_proxy=http://10.81.XXX.XX:8080
prabhakk-mw commented 7 months ago

Thank you @utotch

I've been trying to recreate an environment in which I could test and then possibly fix this issue.

Do you happen to have a way for me to simulate a test environment that represents your setup? If not, perhaps you could share how your environment is configured. For example:

I'll try sharing a docker-compose file which showcases the configuration that I am testing under as well.

Thanks!

prabhakk-mw commented 7 months ago

Hi @utotch

Could you please try again after upgrading to the latest version of the package?

utotch commented 7 months ago

Hi, @prabhakk-mw I checked the latest version, and it successfully worked!!

I appreciate you fixing this issue a lot!!

I suffered from this issue for a long time, preventing me from utilizing matlab-docker. This solution helps a lot with my work.

Have a great day!