error with cBioPortal web API in Python - response 302

74 views
Skip to first unread message

matteo....@gmail.com

unread,
Sep 1, 2022, 10:21:33 AM9/1/22
to cBioPortal for Cancer Genomics Discussion Group
Hi everyone,

I'm trying to use cBioPortal web API using Python and the bravado package, following the documentation on the website. It looks like SwaggerClient raises an exception instead of returning the initialised object, as the API endpoint responds with message 302 (see full trace below). I also tried using the cbio_py Python package and I get the exact same error. I tested this from two different computers with different OSs, different networks and Python versions.

I've also tried using the cBioPortalData R package, and that seems to be working correctly on the same OS/network (at least, I can download the study list):

> cbio <- cBioPortal()
> studies <- getStudies(cbio, buildReport = TRUE)
> studies
# A tibble: 354 × 15
   name    descr…¹ publi…² groups status impor…³ allSa…⁴ readP…⁵ studyId cance…⁶
   <chr>   <chr>   <lgl>   <chr>   <int> <chr>     <int> <lgl>   <chr>   <chr>
 1 Adreno… "TCGA … TRUE    "PUBL…      0 2022-0…      92 TRUE    acc_tc… acc

am I doing something wrong or is there any problem with the web API?

Many thanks!

Follows Python trace:

In [1]: from bravado.client import SwaggerClient
In [2]: cbioportal = SwaggerClient.from_url('https://www.cbioportal.org/api/api-docs',
   ...:                                     config={"validate_requests":False,"validate_responses":False,"validate_swagger_spec": False})
---------------------------------------------------------------------------
HTTPFound                                 Traceback (most recent call last)
Input In [2], in <cell line: 1>()
----> 1 cbioportal = SwaggerClient.from_url('https://www.cbioportal.org/api/api-docs',
      2                                     config={"validate_requests":False,"validate_responses":False,"validate_swagger_spec": False})

File ~/py38/lib/python3.10/site-packages/bravado/client.py:98, in SwaggerClient.from_url(cls, spec_url, http_client, request_headers, config)
     96 http_client = http_client or RequestsClient()
     97 loader = Loader(http_client, request_headers=request_headers)
---> 98 spec_dict = loader.load_spec(spec_url)
    100 # RefResolver may have to download additional json files (remote refs)
    101 # via http. Wrap http_client's request() so that request headers are
    102 # passed along with the request transparently. Yeah, this is not ideal,
    103 # but since RefResolver has new found responsibilities, it is
    104 # functional.
    105 if request_headers is not None:

File ~/py38/lib/python3.10/site-packages/bravado/swagger_model.py:105, in Loader.load_spec(self, spec_url, base_url)
     94 def load_spec(self, spec_url, base_url=None):
     95     """Load a Swagger Spec from the given URL
     96
     97     :param spec_url: URL to swagger.json
     98     :param base_url: TODO: need this?
     99     :returns: json spec in dict form
    100     """
    101     response = request(
    102         self.http_client,
    103         spec_url,
    104         self.request_headers,
--> 105     ).result()
    107     content_type = response.headers.get('content-type', '').lower()
    108     if is_yaml(spec_url, content_type):

File ~/py38/lib/python3.10/site-packages/bravado/http_future.py:282, in HttpFuture.result(self, timeout)
    279 if 200 <= incoming_response.status_code < 300:
    280     return incoming_response
--> 282 raise make_http_exception(response=incoming_response)

HTTPFound: 302

Many thanks

debr...@mskcc.org

unread,
Sep 1, 2022, 10:35:31 AM9/1/22
to matteo....@gmail.com, cbiop...@googlegroups.com, od...@nyu.edu, mram...@gmail.com, whit...@mskcc.org, lu...@ds.dfci.harvard.edu

Hi Matteo,

 

The 302 is because the api-docs page has moved.

 

In the code examples one needs to change:

 

https://www.cbioportal.org/api/api-docs

 

To:

 

https://www.cbioportal.org/api/v2/api-docs  

 

CC’ing a few API client builders to make them aware. It’s a HTTP redirect code, so some clients might automatically follow the redirect (like your browser), but many of the programmatic clients won’t

 

Hope that helps! Apologies for this issue (had to do with our Swagger API upgrade)

 

Thanks!
Ino

--
You received this message because you are subscribed to the Google Groups "cBioPortal for Cancer Genomics Discussion Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cbioportal+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/cbioportal/edbaaeb7-36ee-4dd3-b652-73a764dbc37fn%40googlegroups.com.



*** Only open attachments or links from trusted senders. Report phishing to inf...@mskcc.org ***

 

=====================================================================

Please note that this e-mail and any files transmitted from
Memorial Sloan Kettering Cancer Center may be privileged, confidential,
and protected from disclosure under applicable law. If the reader of
this message is not the intended recipient, or an employee or agent
responsible for delivering this message to the intended recipient,
you are hereby notified that any reading, dissemination, distribution,
copying, or other use of this communication or any of its attachments
is strictly prohibited. If you have received this communication in
error, please notify the sender immediately by replying to this message
and deleting this message, any attachments, and all copies and backups
from your computer.

matteo....@gmail.com

unread,
Sep 1, 2022, 10:47:07 AM9/1/22
to cBioPortal for Cancer Genomics Discussion Group
Dear Ino,

thank you for your prompt reply - I understand. 
Indeed, it works perfectly after switching to the new endpoint.

Kind regards,
Matteo

ps: I'll get back to you ASAP about my other message as well - thanks for that!

debr...@mskcc.org

unread,
Sep 1, 2022, 3:32:43 PM9/1/22
to matteo....@gmail.com, cbiop...@googlegroups.com

Great! Glad to hear! Let us know if you run into any other issues

Reply all
Reply to author
Forward
0 new messages