2

I have a critical issue. I would like integrate my application with another much older application. This service is simply a web form, probably behind a framework (I think ASP Classic maybe). I have an action URL, and I have the HTML code for replicating this service.

This is a piece of the old service (the HTML page):

<FORM method="POST"
    url="https://host/path1/path2/AdapterHTTP?action_name=myactionWebAction&NEW_SESSION=true"
    enctype="multipart/form-data">

    <INPUT type="text" name="AAAWebView-FormAAA-field1" />
    <INPUT type="hidden" name="AAAWebView-FormAAA-field2" value="" />
    <INPUT type="submit" name="NAV__BUTTON__press__AAAWebView-FormAAA-enter" value="enter" />
</FORM>

My application should simulate form submission of this old application from code-behind with Python. For now, I didn't have so much luck.

For now I do this

import requests
payload = {'AAAWebView-FormAAA-field1': field1Value, \
    'AAAWebView-FormAAA-field2': field2Value, \
    'NAV__BUTTON__press__AAAWebView-FormAAA-enter': "enter"
}
url="https://host/path1/path2/AdapterHTTP?action_name=myactionWebAction&NEW_SESSION=true"
headers = {'content-type': 'multipart/form-data'}
r = requests.post(url, data=payload, headers=headers)
print r.status_code

I receive a 200 HTTP response code, but if I click on submit button on the HTML page, the action saves the values, but my code does not do the same. How do I fix this problem?


The owner of an old application sent me this Java exception log. Any ideas?

org.apache.commons.fileupload.FileUploadException: the request was rejected because no multipart boundary was found
Bill the Lizard
  • 398,270
  • 210
  • 566
  • 880
Matte
  • 139
  • 3
  • 14
  • What is `r.text`, Just becuase you are hitting the correct url doesn't mean your request is correct. If you are missing data, or have invalid data. – dm03514 Apr 19 '12 at 16:31

1 Answers1

5

Try passing an empty dictionary as files with requests.post. This will properly construct a request with multipart boundary I think.

r = requests.post(url, data=payload, headers=headers, files={})
Imran
  • 87,203
  • 23
  • 98
  • 131