Closed terminalmage closed 4 years ago
I wasn't able to reproduce your issue, so i wasn't able to understand your problem.
For testing purpose I usually use this demo server.
My last test on that was:
from rtkit.resource import RTResource
from rtkit.authenticators import CookieAuthenticator
from rtkit.errors import RTResourceError
from rtkit import set_logging
import logging
set_logging('debug')
logger = logging.getLogger('rtkit')
url = 'http://rt.easter-eggs.org/demos/stable/REST/1.0/'
resource = RTResource(url, 'john.foo', 'john.foo', CookieAuthenticator)
try:
params = {
'content' :{
'Action' : 'comment',
'Text' : 'Comment with attach',
'Attachment' : 'x.txt, 100x100.gif',
},
'attachment_1' : file('x.txt'),
'attachment_2' : file('100x100.gif'),
}
response = resource.post(path='ticket/270/comment', payload=params,)
for r in response.parsed:
for t in r:
logger.info(t)
except RTResourceError as e:
logger.error(e.response.status_int)
logger.error(e.response.status)
logger.error(e.response.parsed)
with this result:
[DEBUG] POST ticket/270/comment
[DEBUG] {'Content-Length': '838', 'Content-Type': 'multipart/form-data; boundary=xXXxXXyYYzzz', 'Accept': 'text/plain'}
[DEBUG] '--xXXxXXyYYzzz\r\nContent-Disposition: form-data; name="content"\r\nContent-Type: text/plain; charset=utf-8\r\nContent-Length: 72\r\n\r\nAction: comment\nText: Comment with attach\nAttachment: x.txt, 100x100.gif\r\n--xXXxXXyYYzzz\r\nContent-Disposition: form-data; name="attachment_2"; filename="100x100.gif"\r\nContent-Type: image/gif\r\nContent-Length: 336\r\n\r\nGIF87ad\x00d\x00\xe3\x00\x00\xcc\xcc\xcc\x96\x96\x96\xb1\xb1\xb1\xa3\xa3\xa3\xc5\xc5\xc5\xbe\xbe\xbe\xb7\xb7\xb7\x9c\x9c\x9c\xaa\xaa\xaa\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00,\x00\x00\x00\x00d\x00d\x00\x00\x04\xfe\x10\xc8I\xab\xbd8\xeb\xcd\xbb\xff`(\x8edi\x9eh\xaa\xael\xeb\xbep,\xcftm\xdfx\xae\xef|\xef\xff\xc0\xa0pH,\x1a\x8f\xc8\xa4r\xc9l:\x9f\xd0\xa8tJ\xadZ\xaf\xd8\xacv\xcb\xedz\xbf\xe0\xb0xL.\x9b\xcf\xe8\xb4z\xcdn\xbb\xdfp\xab 0)\x1c\x0e\x04\x89\x1d\xdf\x99\xd7\xefy\x00{\x81F\x03\x03t\x12\x07\x02\x08\x08\x89\x8b\x8d\x1b\x86\x88\x00\x8a\x8c\x8e\x96G\x04\x05\x88\x04\x01\x04\x06\x07\x00\x9d\x9f\xa1\x13\x01\x9e\xa7\x13\x9a\x9c\x9e\xa0\xa2\xad\xa5G\x9bzt\xb3\xb6\x93\xa2\x07\x03|u\x88\xb7\x82\xb5\xb8E\xb3\xc0\xc5\xbf\x14\x06\x01\x06\x15\xc4\xbf\xc7\xb2\xac\x9a\xa1\xa3v\x15\x08\x01\x90\xbd\x12\xd4\xd3\x9e\xd5H\xc9\x81\x95\x90\xe3\x14\x9d\xe1\xc8\x9e\x97\xe4\x8fI\xa7\xbe\x80z\xf1\xa6\x03\x00\x87\x14\xef\xf2\xbc\x83q\xfd\xfe\xff\x00\x03\n\x1cH\xb0\xa0\xc1\x83\x08\x13*\\\xc8\xb0\xa1\xc3\x87\x10#J\x9cH\xb1\xa2\xc5\x8b\x183j\xdc\xc8\xb1\xa3\xc7\x8f\x06 C\x8a\xbc\x10\x01\x00;\r\n--xXXxXXyYYzzz\r\nContent-Disposition: form-data; name="attachment_1"; filename="x.txt"\r\nContent-Type: text/plain\r\nContent-Length: 4\r\n\r\nbye\n\r\n--xXXxXXyYYzzz--\r\n'
[INFO] POST
[INFO] http://rt.easter-eggs.org/demos/stable/REST/1.0/ticket/270/comment
[DEBUG] HTTP_STATUS: 200 OK
[DEBUG] 'RT/4.0.5-116-g591e06a 200 Ok\n\n# Message recorded\n\n'
[DEBUG] RESOURCE_STATUS: 200 Ok
[INFO] [[]]
You could see the real result here
Be quick because they reset the db everyday
Yeah, I was able to see the result. I will test using that gif and see if it still works. The file I am trying to attach is a gzipped binary grammar for Nuance.
Any news?
No, sorry. Other things have consumed my time at work recently. I will try to test sometime in the next couple days. Thanks for the reminder.
Couldn't the binary file be mangled because it was being url_quoted? I recently had some trouble while sending a XML as an attachment (It was being escaped, so it ended up attaching a invalid XML to the ticket).
I can get text attachments to work just fine. I used the Comment on a Ticket with Attachments instructions from here, but the ascii text file uploads just fine while RT shows the binary file that I attached as mimetype text/plain, at about double the original size of the file. I even tried using binary mode in my call to file(), like so:
However, the result was the same.