Smartling / api-sdk-python

SDK for integrating with the Smartling API. The Smartling API allows developers to upload language specific resource files and download the translations of those files for easy integration within their application.
http://docs.smartling.com
14 stars 17 forks source link

Inappropriate use of `print` #57

Open Toreno96 opened 1 year ago

Toreno96 commented 1 year ago

In multiple places in your SDK, you're using print outside the examples:

$ fd --exclude 'example' -X rg print
./HttpClient.py
95:            print("Non 200 response:%s   RequestId:%s   URL:%s   response:%s" %

./ObsoleteSmartlingFileApi.py
34:        for k,v in response.items(): print k, ':' ,v

./MultipartPostHandler.py
78:                    print("Replacing %s with %s" % (request.get_header('content-type'), 'multipart/form-data'))

./SmartlingProjectsApiV2.py
32:        for k,v in response.items(): print k, ':' ,v

./SmartlingFileApiV2.py
33:        for k,v in response.items(): print k, ':' ,v

./AuthClient.py
53:            print(e)

./FileApiBase.py
98:            print ("code:%d RequestId:%s jsonBody=%s" % (code, rId, jsonBody))

e.g. https://github.com/Smartling/api-sdk-python/blob/f65d52b2361dbc29730ad82c85e7bbe7df644043/smartlingApiSdk/HttpClient.py#L95-L97

That leads to unexpected results for the users (myself included):

In [18]: resp, status = jobs_api.getJobDetails('foo')
Non 200 response:404   RequestId:Unknown   URL:https://api.smartling.com/jobs-api/v3/projects/3bea86d16/jobs/foo   response:b'{"response":{"code":"NOT_FOUND_ERROR","errors":[{"key":"not.found","message":"Translation job is not found","details":null}]}}'

Note that the error is printed to the standard output. This is unexpected because in the app I'm integrating Smartling into, I would check for status and then log resp.errors or raise an exception. That print would be a redundant noise injected into the app normal output (logs and warnings, primarily).

I think you should consider either removing those prints (if those are accidental debug prints) or replacing them with (debug-level?) logging (which I know you're already configured and use in other places)—depending on each case, I believe.