Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

executing examples/submit_file.py on local instance of snovault #313

Open
annashch-insitro opened this issue Dec 21, 2020 · 1 comment
Open

Comments

@annashch-insitro
Copy link

Hello, I have snovault running on an ec2 vm on localhost:6543
I am attempting to execute https://github.com/ENCODE-DCC/snovault/blob/dev/examples/submit_file.py to store metadata for an example fastq. I get an authentication error:

Calculating md5sum.
Validating file.
Submitting metadata.
Submission failed: 401 Unauthorized
{"@type": ["HTTPUnauthorized", "Error"], "status": "error", "code": 401, "title": "Unauthorized", "description": "This server could not verify that you are authorized to access the document you requested.  Either you supplied the wrong credentials (e.g., bad password), or your browser does not understand how to supply the credentials required."}
Traceback (most recent call last):
  File "submit_file.py", line 154, in <module>
    r.raise_for_status()
  File "/opt/anaconda3/lib/python3.7/site-packages/requests/models.py", line 940, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url: https://localhost:6543/file

I am assuming the issue is here https://github.com/ENCODE-DCC/snovault/blob/dev/examples/submit_file.py#L14 (encoded_access_key and encoded_secret_access_key). How do I determine what goes into these fields? My AWS keys are not working.

Thank you!

@keenangraham
Copy link
Contributor

keenangraham commented Dec 22, 2020

Wow, that's a pretty old file that I'm not sure anyone uses anymore so can't say it works as expected (I think most submitters use https://github.com/StanfordBioinformatics/encode_utils now, but not sure it translates).

In general when posting/patching/getting anything that requires authentication you should add an access key to a user's profile. Not sure snovault looks exactly the same but on portal it looks like this (I deleted this key):

Screen Shot 2020-12-22 at 9 49 46 AM

Screen Shot 2020-12-22 at 9 39 04 AM

Then you can use that access key and secret access key to gain the same permissions as the user. In Python you can pass these keys to requests.

Change status property of file object:

import requests
auth = ('access_key', 'secret_access_key')
r = requests.patch('https://www.encodeproject.org/files/ENCFF262VBW/', json={'status': 'released'}, auth=auth)

Get (private) file properties:

r = requests.get('https://www.encodeproject.org/files/ENCFF321LTI/', auth=auth)
print(r.json())

I'm assuming if you just generate an access key you can copy it into that script. It looks like it is eventually used in post:

auth=(encoded_access_key, encoded_secret_access_key),

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants