Gcode upload with python and OpenAPI
-
@T3P3Tony Thank you for your help.
What I have tried so far:- Update RRF to 3.6beta4
- Test CURL commands:
F:\temp>curl http://192.168.2.1/rr_connect?password= {"err":0,"sessionTimeout":8000,"boardType":"duet3mb6hc102","apiLevel":2,"sessionKey":0} F:\temp>curl --data-binary @"test.g" "http://192.168.2.1/rr_upload?name=/gcodes/test.g" {"err":0} F:\temp>
No success with Python so far.
What I dont understand is that the Python function generated from OpenAPI has only one parameter "name". The parameters "time" and "crc32" are optional. But at least two variables are required: source(path_and_filename.gcode) and destination(name) like in CURL.
rr_upload_post
Example
from __future__ import print_function import time import swagger_client from swagger_client.rest import ApiException from pprint import pprint # create an instance of the API class api_instance = swagger_client.DefaultApi() name = 'name_example' # str | Path to the file to upload time = '2013-10-20T19:20:30+01:00' # datetime | ISO8601-like represenation of the time the file was last modified (optional) crc32 = 'crc32_example' # str | CRC32 checksum of the file content as hex string *without* leading `0x`. Usage of this parameter is encouraged (optional) try: # Upload a file api_response = api_instance.rr_upload_post(name, time=time, crc32=crc32) pprint(api_response) except ApiException as e: print("Exception when calling DefaultApi->rr_upload_post: %s\n" % e)
Parameters
Name Type Description Notes name str Path to the file to upload time datetime ISO8601-like represenation of the time the file was last modified [optional] crc32 str CRC32 checksum of the file content as hex string without leading `0x`. Usage of this parameter is encouraged [optional] -
@cnc65 said in Gcode upload with python and OpenAPI:
so curl is working, there is an issue with the python implementation or the API description in YAML file
What I don't understand is that the Python function generated from OpenAPI has only one parameter "name". The parameters "time" and "crc32" are optional. But at least two variables are required: source(path_and_filename.gcode) and destination(name) like in CURL.
I think the "name" parameter is the destination path & filename. however the comments in the YAML file imply its the source:
parameters: - name: 'name' in: query description: 'Path to the file to upload' required: true schema: type: string - name: 'time' in: query description: 'ISO8601-like represenation of the time the file was last modified' required: false schema: type: string format: 'date-time' - name: 'crc32' in: query description: 'CRC32 checksum of the file content as hex string *without* leading `0x`. Usage of this parameter is encouraged' required: false schema: type: string
@chrishamm can you help?
-
Is a solution to this problem in progress?
-
undefined cnc65 marked this topic as a question
-
-
@chrishamm can you point to where it is in the API definition? I.e. where is "body" is specified in the definition?
-
-
@chrishamm thanks so this is some issue with swagger?
-
@T3P3Tony Perhaps it was the GET request, not the POST request? I'm not sure.
-
@chrishamm I looked at the swagger post code.
-
@chrishamm @T3P3Tony
I have changed the requestBody in the OpenAPI.yaml file so that a parameter body is generated in Python. This works for uploading gcode files. I have not tested other files.requestBody: required: true description: 'File content' content: application/octet-stream: schema: type: string format: binary
The function call in Python then looks like this:
# Upload a file file = "f:/temp/test.g" name = "0:/gcodes/test-1.g" try: body = open(file).read() duet_response = api_instance.rr_upload_post(body, name) except ApiException as e: print("Exception when calling DefaultApi->rr_upload_post: %s\n" % e)
-
undefined cnc65 has marked this topic as solved