2

I'm migrating from Mechanize to Requests because Mechanize isn't supported yet in Python 3.x. I've come up with this simple script to post data, but the returned page shows an error: Error: Can't load FIXES database!

url = "http://rfinder.asalink.net/free/"
payload = {"id1": "EGLL", "id2": "LOWW"}
r = requests.post(url, payload)

Using mechanize I only had to post the id1 and id2 fields and submit the form. All other fields were default.

I think this is where things go wrong. How do I tell Requests to post all the default data + the id1 and id2 fields?

1
  • 2
    Requests is only an HTTP client library and can't parse and HTML form to get its default field names and values from. You should either manually hardcode those fields in your script or use an HTML parser like BeautifulSoup to parse the form each time and extract field names & default values. Commented Aug 20, 2014 at 20:54

1 Answer 1

1

This is a working example with the hard-coded fields:

import requests

url = "http://rfinder.asalink.net/free/autoroute_rtx.php"

payload = {
    'id1':'lirf',
    'ic1':'',
    'id2':'egll',
    'ic2':'',
    'minalt':'FL330',
    'maxalt':'FL330',
    'lvl':'B',
    'dbid':1408,
    'usesid':'Y',
    'usestar':'Y',
    'easet':'Y',
    'rnav':'Y',
    'nats':'',
    'k':235644007
}

r = requests.post(url, data=payload)

print( r.text )
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.