Skip to content

Commit

Permalink
Use PreparedRequest; print request on 500 error
Browse files Browse the repository at this point in the history
Still trying to debug the intermittent failures
(Docverter/docverter#28)
  • Loading branch information
msabramo committed Feb 2, 2015
1 parent 6c71193 commit ac1238e
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions docverter.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,28 @@ def _process_file(source_text, to_format, from_format, extra_args):
temp_file.write(source_text)
temp_file.seek(0)

resp = requests.post(
url,
req = requests.Request(
'POST', url,
data={'from': from_format, 'to': to_format},
files={'input_files[]': temp_file},
)
prepared = req.prepare()
session = requests.Session()
resp = session.send(prepared)
# import pdb; pdb.set_trace()
if resp.ok:
return resp.text
else:
if resp.status_code == 500:
req = prepared
print('**** Got a 500 error from server *****')
print('{}\n{}\n{}\n\n{}'.format(
'-----------START-----------',
req.method + ' ' + req.url,
'\n'.join('{}: {}'.format(k, v)
for k, v in req.headers.items()),
req.body,
))
print('temp_file = %r' % temp_file)
print('temp_file.name = %r' % temp_file.name)
raise RuntimeError(
Expand Down

0 comments on commit ac1238e

Please sign in to comment.