-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
LILT-API header is not used #22
Comments
Checked using local python server to dump headers:
|
Hi @maharg101 thanks for raising this issue. Could you share an example of the code that you're using? Did you create the project beforehand as well? The You are correct that this library doesn't use the I'm not running into any issues with document uploads using this library. Here is a working example snippet (be sure to set the correct from lilt import Configuration, ApiClient, DocumentsApi
def main():
API_KEY = 'example_key'
PROJECT_ID = 5555
configuration = Configuration(
api_key={'key': API_KEY}
)
api_client = ApiClient(configuration)
documents_api = DocumentsApi(api_client)
with open('test.docx', 'rb') as f:
body = f.read()
documents_api.upload_document('test.docx', PROJECT_ID, body)
if __name__ == '__main__':
main() |
Hi @tgallant Yes, the project exists, and works with curl examples using the The code I am using (invoked by the main script):
I am working against a private instance. I was not involved in deploying it, but could find out some details. It is possible therefore that the installation is not forwarding the relevant headers to the API. |
Hi @maharg101 thanks for the note
That sounds like something worth investigating. Maybe there is some proxy server that is stripping certain headers. As a workaround you can construct a request that uses the import json
from lilt import Configuration, ApiClient, DocumentsApi
def main():
API_KEY = 'example_key'
PROJECT_ID = 5555
configuration = Configuration(
api_key={'key': API_KEY}
)
api_client = ApiClient(configuration)
documents_api = DocumentsApi(api_client)
upload_opts = {
'name': 'test.docx',
'project_id': PROJECT_ID,
'pretranslate': 'tm+mt'
}
headers = {
'LILT-API': json.dumps(upload_opts),
'Content-Type': 'application/octet-stream'
}
with open('test.docx', 'rb') as t:
body = t.read()
# self.api_instance.api_client.call_api() in your case
res = documents_api.api_client.call_api(
'/documents/files',
'POST',
body=body,
header_params=headers,
query_params=[],
auth_settings=['ApiKeyAuth', 'BasicAuth'],
response_type='DocumentWithoutSegments',
_return_http_data_only=True
)
print(res.id)
if __name__ == '__main__':
main() Let me know if that's a suitable workaround or if you have further questions. |
Thanks @tgallant - that works well. Are there any plans to have this library use the LILT-API header ? |
The main complication is that this library is being generated from an API specification using openapi-generator. The OpenAPI standard doesn't have a mechanism for serializing/stringifying a JSON object inside of a header parameter. Instead we've opted to support passing in each parameter as a separate header value. Here is the documentation for how different types of parameters are serialized in OpenAPI: https://swagger.io/docs/specification/serialization/ It looks like OpenAPI supports serializing complex objects into a single header parameter like so
We would have to add support for handling parameters sent in this format on the server side in order to enable this in the client library. Let me discuss this internally with the team. |
It seems that the
LILT-API
header is not used. Instead individual values, such asproject_id
are sent in their own headers.The only references to
LILT-API
appear to be in the commentary / documentation. A search confirms this: https://github.com/lilt/lilt-python/search?q=LILT-APII have traced the headers including
project_id
through to theurllib3.request()
method, and they are not passed as a JSON object with the header fieldLILT-API
.Consequently, a call to the upload_document endpoint results in a bad request
HTTP response body: {"message":"Invalid request: missing project_id header"}
The text was updated successfully, but these errors were encountered: