0

I am trying to programmatically use this tool http://www.idtdna.com/calc/analyzer so that I can batch analyze a few dozen DNA sequences.

Peeking inside Chrome's developer tools, I see that I am sending a POST request when I click the Analyze button (after entering a sequence (eg "AACCGGTT") in the Sequence field). In the Response tab, I can also see the response (eg "MeltTemp") that I wish to collect. So, following the tutorial (http://docs.python-requests.org/en/latest/user/quickstart/#make-a-request), I put together the snippet below, but it's clearly not working.

>>> import requests
>>> url = 'http://www.idtdna.com/calc/analyzer/home/analyze' # from: ChromeDevTools -> Network -> Name: analyze -> tab: Headers -> General -> Request URL
>>> data = {"settings":{"Sequence":"AACCGGTT", # from: ChromeDevTools -> Network -> Name: analyze -> tab: Headers -> Request Payload
 "NaConc":50,
 "MgConc":0,
 "DNTPsConc":0,
 "OligoConc":0.25,
 "NucleotideType":"DNA",
 }}
>>> r = requests.post(url, data=data)
>>> r.url # 404 page
u'http://www.idtdna.com/404.aspx?aspxerrorpath=/calc/analyzer/home/analyze'
# I was hoping for something like this that gives me the JSON response (which can be found at
# ChromeDevTools -> Network -> Name: analyze -> tab: Response)
>>> r.some_magical_function()
{"Sequence":"AAC CGG TTG GTT AAT T","NaConc":50, ... "MeltTemp":45.1, ...}

What am I missing?

Does the post request need to be way more complicated (with cookies? session??)? If so, please provide pointers to what I need to learn (or the solution :p)

I understand if the website has safeguards against this kind of usage; if it's basically impossible, then what strategy do you suggest?selenium?

asked Mar 15, 2016 at 6:52
4
  • idtdna.com/calc/analyzer/home/analyze does not exist, it returns 404 Not Found. Why do you think this is the URL to POST to? Commented Mar 15, 2016 at 6:56
  • It seems that the web site makes the POST request to sg.idtdna.com/calc/analyzer/home/analyze instead Commented Mar 15, 2016 at 7:03
  • 1
    I am voting to close this question, because this question was caused by a problem that can no longer be reproduced or a simple typographical error. While similar questions may be on-topic here, this one was resolved in a manner unlikely to help future readers. This can often be avoided by identifying and closely inspecting the shortest program necessary to reproduce the problem before posting. Commented Mar 15, 2016 at 7:10
  • As commented below, I thought it was www (instead of the sg, as pointed out by niemmi) based on the request: ChromeDevTools -> Network -> Name: analyze -> tab: Headers -> General -> Request URL. Perhaps this is not where I should get the POST address...??? Commented Mar 15, 2016 at 15:39

1 Answer 1

2

import requests
url = 'http://sg.idtdna.com/calc/analyzer/home/analyze'
data = {
 'settings': {
 'Sequence': 'AACCGGTT',
 'NaConc': 50,
 'MgConc': 0,
 'DNTPsConc': 0,
 'OligoConc': 0.25,
 'NucleotideType': 'DNA',
 }
}
s = requests.Session()
s.get('http://sg.idtdna.com/calc/analyzer') # to set cookies
r = s.post(url, json=data)
print(r.json())

UPDATE

Depending on location, redirection does not happen. In such case use www.idtdna.com instead of sg.idtdna.com.

answered Mar 15, 2016 at 7:13
Sign up to request clarification or add additional context in comments.

7 Comments

Could you tell me where/how to find the correct url? I thought it was www (instead of the sg) based on the request: ChromeDevTools -> Network -> Name: analyze -> tab: Headers -> General -> Request URL. I can't seem to find anywhere the sg address...
Also, @falsetru, is this solution tested? I get: print(r.json()) ValueError: No JSON object could be decoded and r.url is the 404 page I mentioned in the question....
thx for the demo, appreciate it. but now I'm confused... because I don't get redirected. see: i.imgur.com/YNsJLXF.jpg How should I go about debugging this?
@obk, What do you get if you replace all occurences of sg with www in the anser code, and run it?
|

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.