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
189 stars 109 forks source link

Error message 'NoneType' object has no attribute 'text' was encountered #647

Closed drerrolb closed 2 years ago

drerrolb commented 2 years ago

Error I've developed a python application with TM1py and am successfully reading from cubes. However, when I deploy this application to http://pythonanywhere.com for testing, using the exact same code, I get the error message " Error message 'NoneType' object has no attribute 'text' was encountered" at the point where the TM1Service is instantiated.

try:
    with TM1Service(**config['tm1']) as tm1:
        if tm1.connection.is_connected:
            logging.info('TM1 service connected')
            logging.info('Version: ' + tm1.server.get_product_version())
            logging.info('Server: ' + tm1.server.get_server_name())
            logging.info('Product: ' + tm1.server.get_product_version())

except Exception as e:
    logging.warning('Error message ' + str(e) + ' was encountered')
    exit(1)

Local Server NFO:root:Retrieving the configuration INFO:root:Base URL: https://xxxxxxx.planning-analytics.cloud.ibm.com/tm1/api/xxxxx/ INFO:root:User: xxxxxxx INFO:root:Namespace: LDAP INFO:root:Verify: True INFO:root:Asynch: True INFO:root:TM1 service connected INFO:root:Version: 11.8.00800.5 INFO:root:Execution finished INFO:root:Finished successfully

pythonanywhere server 2021-11-30 09:01:42,078: Base URL: https://xxxxxxx.planning-analytics.cloud.ibm.com/tm1/api/xxxxx/ 2021-11-30 09:01:42,078: User: xxxxxxx 2021-11-30 09:01:42,078: Namespace: LDAP 2021-11-30 09:01:42,078: Verify: True 2021-11-30 09:01:42,079: Asynch: True 2021-11-30 09:01:42,085: Error message 'NoneType' object has no attribute 'text' was encountered

Although I'm guessing there's some kind of restriction on the pythonanywhere site, I'm suggesting this as a bug because the error appears to be unhandled.

To Reproduce To reproduce, take a working tm1py script and upload it to http://pythonanywhere.com.

Expected behavior Ideally, the script should perform the same way that it does locally, however I understand that there may be some issues, so I would expect a meaningful error to be returned.

Version TM1py (local) 1.8.0 TM1py (pythonanywhere) 1.8.0 TM1 Server Version: 11.8.00800.5

MariusWirtz commented 2 years ago

Hi @drerrolb,

this error happens when the requests library returns None instead of a response. We actually fixed the handling of this situation few weeks ago, but we haven't release it to PyPI yet. https://github.com/cubewise-code/tm1py/commit/a42753efd089f8179213596f0ce38001d53822c0

if you are looking for a more helpful error message, please upgrade to the current master branch:

pip uninstall tm1py
pip install https://github.com/cubewise-code/tm1py/archive/refs/heads/master.zip

However, the real problem is that no response is returned to the tm1py script. Please double check the base_url and potential security settings on the server (firewall, etc.). Like you said it's probably some restriction of the pythonanywhere site.

I appreciate that you reported the error.

rkvinoth commented 2 years ago

@MariusWirtz I typed all this, so I'm just going to put it there :P

@drerrolb This unhandled error has been fixed in the lasted master branch. You can upgrade to it using pip install https://github.com/cubewise-code/tm1py/archive/master.zip --upgrade I'm not sure how you can do this in that website (never used that website before).

Coming back to your issue, it means that the connection to your TM1 instance is not successful. As far as I know, IBM cloud isn't suppressed by firewall and can be accessed from anywhere if you have the interactive account details. So, check the parameters you are passing (Base URL, username, password).

drerrolb commented 2 years ago

Thanks @MariusWirtz and @rkvinoth for the response.

Yes, as expected, I've confirmed that the http://pythonanywhere.com site restricts outbound requests on their free accounts.

Thank you also for your time and effort developing TM1py.

MariusWirtz commented 2 years ago

Thanks for confirming!