GithubHelp home page GithubHelp logo

docraptor-python's Issues

SSL Cert verification failing with new Docraptor client on Linux/Python client docraptor 0.2.1

We are running Linux OpenSuse LEAP 42.1.

With the latest docraptor==0.2.1 client (Python) we receive the folloing error (likely because of some issue with the local cert store of OpenSuse. I suggest that the Python API should receive an optional parameter verify_cert=True|False (True by default) in order to have a workaround without hacking the Docraptor sources.

Andreas

https://docraptor.com//docs 
Traceback (most recent call last): 
 File "test.py", line 43, in <module> 
   "document_type": "pdf",                                         # pdf or xls or xlsx 
 File "/data/home/ajung/src/zopyx_ne.no/lib/python2.7/site-packages/docraptor/apis/doc_api.py", line 203, in create_doc 
   callback=params.get('callback')) 
 File "/data/home/ajung/src/zopyx_ne.no/lib/python2.7/site-packages/docraptor/api_client.py", line 325, in call_api 
   response_type, auth_settings, callback) 
 File "/data/home/ajung/src/zopyx_ne.no/lib/python2.7/site-packages/docraptor/api_client.py", line 149, in __call_api 
   post_params=post_params, body=body) 
 File "/data/home/ajung/src/zopyx_ne.no/lib/python2.7/site-packages/docraptor/api_client.py", line 361, in request 
   body=body) 
 File "/data/home/ajung/src/zopyx_ne.no/lib/python2.7/site-packages/docraptor/rest.py", line 204, in POST 
   body=body) 
 File "/data/home/ajung/src/zopyx_ne.no/lib/python2.7/site-packages/docraptor/rest.py", line 165, in request 
   raise ApiException(status=0, reason=msg) 
docraptor.rest.ApiException: (0) 
Reason: SSLError 
[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:581)

Python 3 Support

Using the sample code from the README

$ python3 ./dr.py
Traceback (most recent call last):
  File "./dr.py", line 13, in <module>
    "document_type": "pdf",                                         # pdf or xls or xlsx
  File "/usr/local/lib/python3.5/site-packages/docraptor/apis/doc_api.py", line 203, in create_doc
    callback=params.get('callback'))
  File "/usr/local/lib/python3.5/site-packages/docraptor/api_client.py", line 322, in call_api
    response_type, auth_settings, callback)
  File "/usr/local/lib/python3.5/site-packages/docraptor/api_client.py", line 149, in __call_api
    post_params=post_params, body=body)
  File "/usr/local/lib/python3.5/site-packages/docraptor/api_client.py", line 358, in request
    body=body)
  File "/usr/local/lib/python3.5/site-packages/docraptor/rest.py", line 208, in POST
    body=body)
  File "/usr/local/lib/python3.5/site-packages/docraptor/rest.py", line 171, in request
    r.data = r.data.decode('utf8')
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe2 in position 10: invalid continuation byte

Add binary corruption test

It's easy for generated clients to return accidentally utf8 encoded data, which ends up corrupting PDF/XLS/XLSX files. Let's add a test to ensure this can never happen.

Remove beta status

Python packages support setting the alpha/beta/production status of a build. We started with beta but I think it's time we go to production ready / stable.

Update openapi-generator to fix urllib3 deprecation warning

After updating urllib3 to more recent version (due to CVE-2023-43804) I'm seeing following warning:

[REDACTED].py: in generate_pdf
    response = doc_api.create_async_doc(options)
../venv/lib/python3.10/site-packages/docraptor/api/doc_api.py:67: in create_async_doc
    return self.create_async_doc_with_http_info(doc, **kwargs)  # noqa: E501
../venv/lib/python3.10/site-packages/docraptor/api/doc_api.py:172: in create_async_doc_with_http_info
    return self.api_client.call_api(
../venv/lib/python3.10/site-packages/docraptor/api_client.py:378: in call_api
    return self.__call_api(resource_path, method,
../venv/lib/python3.10/site-packages/docraptor/api_client.py:185: in __call_api
    response_data = self.request(
../venv/lib/python3.10/site-packages/docraptor/api_client.py:422: in request
    return self.rest_client.POST(url,
../venv/lib/python3.10/site-packages/docraptor/rest.py:272: in POST
    return self.request("POST", url,
../venv/lib/python3.10/site-packages/docraptor/rest.py:231: in request
    raise ApiException(http_resp=r)
../venv/lib/python3.10/site-packages/docraptor/exceptions.py:110: in __init__
    self.headers = http_resp.getheaders()
../venv/lib/python3.10/site-packages/docraptor/rest.py:42: in getheaders
    return self.urllib3_response.getheaders()
../venv/lib/python3.10/site-packages/urllib3/response.py:667: in getheaders
    warnings.warn(
E   DeprecationWarning: HTTPResponse.getheaders() is deprecated and will be removed in urllib3 v2.1.0. Instead access HTTPResponse.headers directly.

This issue has been fixed in this PR of openapi-generator and that the fix was released on version v6.4.0, but this repository is using an older version:

Wrong return type in doc creation docstrings, provides incorrect guidance to type checkers

The DocApi.create_doc() method's docstring includes the wrong return type:

:return: Returns the result object.
If the method is called asynchronously,
returns the request thread.
:rtype: str

Similarly for DocApi.create_doc_with_http_info:

:return: Returns the result object.
If the method is called asynchronously,
returns the request thread.
:rtype: tuple(str, status_code(int), headers(HTTPHeaderDict))

The correct return type here are bytes and tuple(bytes, status_code(int), headers(HTTPHeaderDict)), respectively.

Since Python 3, str is reserved for unicode strings, not the byte strings return by HTTP calls.

I know a picture isn't proof but absent a share environment, here's the best I can do.

CleanShot 2023-09-15 at 16 07 57@2x

Why does this matter?

It doesn't affect the working of the library, but it does anyone using any type checking or type hints, e.g. PyCharm below:

CleanShot 2023-09-15 at 16 01 48@2x

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.