TACTIC Open Source
Does checkin with api client tested with python3? - Printable Version

+- TACTIC Open Source (http://forum.southpawtech.com)
+-- Forum: TACTIC Open Source (http://forum.southpawtech.com/forumdisplay.php?fid=3)
+--- Forum: TACTIC Discussion (http://forum.southpawtech.com/forumdisplay.php?fid=4)
+--- Thread: Does checkin with api client tested with python3? (/showthread.php?tid=152)



Does checkin with api client tested with python3? - listy - 07-15-2020

I have been busy porting all my tools to py3.
Tests with upload checkin failed on latest python client api. Does it tested or something wrong with my python?

Code:
Traceback (most recent call last):
  File "<string>", line 5, in <module>
  File "\client\tactic_client_lib\tactic_server_stub.py", line 2017, in simple_checkin
    self.upload_file(file_path)
  File "\client\tactic_client_lib\tactic_server_stub.py", line 1862, in upload_file
    upload.execute(path)
  File "\client\tactic_client_lib\common\upload_multipart.py", line 105, in execute
    (status, reason, content) = self.upload(self.server_url, fields, files)
  File "\client\tactic_client_lib\common\upload_multipart.py", line 120, in upload
    ret_value = self.posturl(url, fields, files)
  File "\client\tactic_client_lib\common\upload_multipart.py", line 145, in posturl
    return self.post_multipart(urlparts[1], urlparts[2], fields,files, protocol)
  File "\client\tactic_client_lib\common\upload_multipart.py", line 155, in post_multipart
    content_type, body = self.encode_multipart_formdata(fields, files)
  File "\client\tactic_client_lib\common\upload_multipart.py", line 233, in encode_multipart_formdata
    buf.writelines(M)
TypeError: string argument expected, got 'bytes'

(I tried to use BytesIO, but no luck)


RE: Does checkin with api client tested with python3? - remkonoteboom - 07-15-2020

I seem to remember we did fix this error. Are you sure you have the latest? The latest file doesn't even go to line 233

https://github.com/Southpaw-TACTIC/TACTIC/blob/4.8/src/client/tactic_client_lib/common/upload_multipart.py

I believe the fix was in this commit:

https://github.com/Southpaw-TACTIC/TACTIC/commit/4f1b88531f8f88498b3e262dc0fddd873edbc19d


RE: Does checkin with api client tested with python3? - listy - 07-15-2020

(07-15-2020, 06:19 PM)remkonoteboom Wrote: I seem to remember we did fix this error.  Are you sure you have the latest?  The latest file doesn't even go to line 233

https://github.com/Southpaw-TACTIC/TACTIC/blob/4.8/src/client/tactic_client_lib/common/upload_multipart.py

I believe the fix was in this commit:

https://github.com/Southpaw-TACTIC/TACTIC/commit/4f1b88531f8f88498b3e262dc0fddd873edbc19d
Yes i have latest.
Some more lines i added by mysef trying to figure out whats wrong.  Wink
The error is the same out of the box on latest version


RE: Does checkin with api client tested with python3? - remkonoteboom - 07-16-2020

Somehow, one of the elements in the array "M" is still a bytes type even though even though this code:


Code:
for l in L:
    try:
        l = l.decode()
    except UnicodeDecodeError as e:
        pass
    except AttributeError as e:
        pass
    M.append(l)
    M.append(CRLF)


i supposed to decode it into a string.  I can see in our code, that the exceptions are just "pass".  Could you actually print out "e" or call "raise" instead or "pass" to see exactly if there are any errors?

Also, we are using "writelines" to quickly take in the entire array at once.  Maybe replacing:


Code:
buf.writelines(M)

with


Code:
for m in M:
    print(m)
    buf.write(m)


will show exactly which line is causing the error.


RE: Does checkin with api client tested with python3? - listy - 07-16-2020

I did this test. The line with bytes type causing the error.
This line contains actual file.
What is the point trying to send bin data as string?
If only string can be sent may be it is good to make bin > hex > hexstring, and then backwards?


RE: Does checkin with api client tested with python3? - remkonoteboom - 07-16-2020

Judging from the style and variable names, most of this was copied from an example from the web. And it just worked in Python 2 and nobody worried about it. Now with Python 3, we have a strong separation between bytes and strings and this has become a problem.


RE: Does checkin with api client tested with python3? - listy - 07-16-2020

Well. My experience with upload process in tactic api was not so well.
1: Almost not possible to track upload process, it is not easy waiting till 1gb file uploading without any process indication
2: Floating crashes when upload process. I don't know why, but it is crashes sometimes, or freezes, and there is no clue why. What i did - a separate process, which is doing upload process separated from Maya or other apps, so i can be sure it will not crash my UI, and Maya.


RE: Does checkin with api client tested with python3? - remkonoteboom - 07-18-2020

The upload has been fixed in the linked pull request. The file is now converted to base64 before adding to the request. You can also set the chunk size in the api, so that a file change be uploaded in chunks. This is now exposed in the API. The default chunk size is 10Mb. There is also an offset counter which if fails, you could theoretically restart at that offset, however, this number is not available to the API function yet.

https://github.com/Southpaw-TACTIC/TACTIC/pull/1514/commits/216ca3070a346989932278d045bdc8089edc3764

Getting progress at the moment would be best done with chunks. At 10Mb chunks, a 1Gb file would have 100 "offsets" to query. Maybe, this could be done with calling the upload in a thread and then polling the thread somehow. Will have to test that.