m2ms / fragalysis-frontend

The React, Redux frontend built by webpack
Other
1 stars 1 forks source link

POST request to legacy fails (wrong environment?) #1450

Open mwinokan opened 3 months ago

mwinokan commented 3 months ago

From ticket in other repo

The following request, directly from the example doesn't work.

import os
import tempfile
import requests

url = "https://fragalysis.diamond.ac.uk/api/download_structures/"

#data is the json you downloaded from Fragalysis
data = {"target_name":"nsp13","proteins":"nsp13-x0029_0A,nsp13-x0034_0B","event_info":False,"sigmaa_info":False,"diff_info":False,"trans_matrix_info":False,"NAN":False,"mtz_info":False,"cif_info":False,"NAN2":False,"map_info":False,"single_sdf_file":True,"sdf_info":False,"pdb_info":False,"bound_info":True,"metadata_info":True,"smiles_info":True,"static_link":False,"file_url":""}

#First get the url of the particular file using the copied json
r = requests.post("https://fragalysis.diamond.ac.uk/api/download_structures/", json=data)
if r.ok:
    #Next, use the returned url to download the actual zip file
    file_url = r.json()["file_url"]
    r = requests.get("https://fragalysis.diamond.ac.uk/api/download_structures?file_url=%s"%file_url, allow_redirects=True)
    if r.ok:
        with open(os.path.basename(file_url), mode="wb") as f:
            f.write(r.content)
else:
    print("failed")
mwinokan commented 3 months ago

@kaliif please post requirements file for a venv that fixes this issue

phraenquex commented 3 months ago

This is the conversation in Slack.

kaliif commented 3 months ago

The problem seems to have been caused by out the out-of-date requests library. Steps to reproduce the working environment:

requirements.txt

alanbchristie commented 3 months ago

I've posted a 'leaner' token-based API example in this public gist.

It works with the existing legacy stack using Python 3.12.3 and requests 2.32.2