cubewise-code / tm1py

TM1py is a Python package that wraps the TM1 REST API in a simple to use library.
http://tm1py.readthedocs.io/en/latest/
MIT License
190 stars 109 forks source link

requests.exceptions.InvalidProxyURL: Please check proxy URL. #98

Closed user1493 closed 5 years ago

user1493 commented 5 years ago

Hi,

I created a python script to export a dimension structure. This script was then converted to an exe file using pyinstaller.

I then called this exe file via cmd in my machine. The exe worked and exported the data. But when I used this exe in another machine, it gave out the highlighted error. Any idea how to sort this out?

code:

import configparser
import os
import sys
cube_name = sys.argv[1]
config = configparser.ConfigParser()
cwd = os.getcwd()
config.read(os.path.join(cwd, 'config.ini'))
metadata_file = os.path.join(cwd, cube_name+'.xlsx')
import pandas as pd
from TM1py.Services import TM1Service
from TM1py.Utils import Utils
with TM1Service(**config['Sales']) as tm1:
    all_cubes = tm1.cubes.get(cube_name)
    dims = all_cubes.dimensions
    with pd.ExcelWriter(metadata_file) as writer:
        for dim in dims:
            df = []
            dimension = tm1.dimensions.get(dim)
            for hierarchy in dimension:
                for element in hierarchy:
                    df.append(element.name)
                pd.DataFrame(df).to_excel(writer, sheet_name=dim, header=False, index=False)

Error:

Traceback (most recent call last): File "dim.py", line 16, in File "site-packages\TM1py\Services\TM1Service.py", line 12, in init File "site-packages\TM1py\Services\RESTService.py", line 96, in init File "site-packages\TM1py\Services\RESTService.py", line 169, in _start_session File "site-packages\requests\sessions.py", line 525, in get File "site-packages\requests\sessions.py", line 512, in request File "site-packages\requests\sessions.py", line 622, in send File "site-packages\requests\adapters.py", line 388, in send File "site-packages\requests\adapters.py", line 292, in get_connection requests.exceptions.InvalidProxyURL: Please check proxy URL. It is malformed and could be missing the host. [10048] Failed to execute script dim

MariusWirtz commented 5 years ago

Did you try running the original python script on the second machine ?

user1493 commented 5 years ago

The second machine does not have python installed in it. I would like to spread my script with many users, that is the reason I created an executable file (python installation not needed).

I tested this in two more machine and facing the same issue.

user1493 commented 5 years ago

Is something broken with this url ?https://wa01399d:9049/api/v1/Configuration/ProductVersion/$value

This is the URL passed to the below line of code in RESTServices.py (line 169) self._s.get(url=url, headers=self._headers, data='', verify=self._verify)

This URL works https://wa01399d:9049/api/v1/, but the above one throws error "HTTP error 401".

Does this ring any bell?

user1493 commented 5 years ago

Upon updating TM1py to the latest version, getting the below errors:

Traceback (most recent call last):
  File "find_unused_dimensions.py", line 10, in <module>
  File "site-packages\TM1py\Services\TM1Service.py", line 12, in __init__
  File "site-packages\TM1py\Services\RESTService.py", line 99, in __init__
  File "site-packages\TM1py\Services\RESTService.py", line 177, in _start_session
  File "site-packages\TM1py\Services\RESTService.py", line 30, in wrapper
  File "site-packages\TM1py\Services\RESTService.py", line 119, in GET
  File "site-packages\requests\sessions.py", line 525, in get
  File "site-packages\requests\sessions.py", line 512, in request
  File "site-packages\requests\sessions.py", line 622, in send
  File "site-packages\requests\adapters.py", line 388, in send
  File "site-packages\requests\adapters.py", line 292, in get_connection
requests.exceptions.InvalidProxyURL: Please check proxy URL. It is malformed and could be missing the host.
[13820] Failed to execute script find_unused_dimensions
user1493 commented 5 years ago

My second machine has no proxy enabled, I confirmed the same with netsh winhttp show proxy Output: Current WinHTTP proxy settings: Direct access (no proxy server)

Not sure why the control is getting into if proxy: after proxy = select_proxy(url, proxies)

So I removed the below lines (288 - 296) from adapters.py and created the executable file again. I used this new executable file in the second machine, now the file worked successfully.

        if proxy:
            proxy = prepend_scheme_if_needed(proxy, 'http')
            proxy_url = parse_url(proxy)
            if not proxy_url.host:
                raise InvalidProxyURL("Please check proxy URL. It is malformed"
                                      " and could be missing the host.")
            proxy_manager = self.proxy_manager_for(proxy)
            conn = proxy_manager.connection_from_url(url)
        else:

I used this as a workaround, please let me know how to fix this permanently.

MariusWirtz commented 5 years ago

This seems to be an issue in the underlying requests library. You can open an issue here.

user1493 commented 5 years ago

I raised an issue there some four days back, but not getting any response.

Have added a comment. Let's hope for the best outcome.

MariusWirtz commented 5 years ago

OK. Thanks for the update. I will close this issue.

user1493 commented 5 years ago

Please try to replicate the issue from your end if possible and provide your comments there.

Thank you very much for your valuable support!