<p>Okay, I finally solved it. The reason was the <code>EGA_CLIENT_ID</code> variable. In the <code>pyega3.py</code> <a href="https://github.com/EGA-archive/ega-download-client/blob/master/pyega3/pyega3.py" rel="nofollow noreferrer">script</a>, there is a definition for the <code>client_id</code> for pyega3 v3.0.44 ("f20cd2d3-682a-4568-a53e-4262ef54c8f4"). After setting the <code>EGA_CLIENT_ID</code> to this value login was successful. </p>

<pre><code>os.environ["EGA_CLIENT_ID"] = "f20cd2d3-682a-4568-a53e-4262ef54c8f4"
</code></pre>

<p>I think this is a bug and I filed it on Snakemake's git repository - the official documentation just requires definition of the <code>EGA_USERNAME</code> and <code>EGA_PASSWORD</code> variables, and while definition of <code>EGA_CLIENT_SECRET</code> will probably need to be done by the user, the client ID should be pulled automatically from the pyega3 version installed locally. </p>

<p>Of note, after successful login, the example download from the documentation failed with the following:</p>

<pre><code>Missing input files for rule a:
ega/EGAD00001002142/COLO_829_EPleasance_TGENPipe.bam.bai
</code></pre>

<p>However, downloading files that I have access to worked, indicating that the paths to the files from the documentation are wrong or are access-protected. </p>

CC BY-SA 4.0
2020-05-08T16:53:44.123Z
2020-05-08T16:53:44.123Z
ben
<p>The example code provided by the <a href="https://snakemake.readthedocs.io/en/stable/snakefiles/remote_files.html" rel="nofollow noreferrer">Snakemake documentation</a> for remote downloading from the EGA archive fails for me. I have defined all required environment variables, but an error comes up stating </p>

<pre><code>{"error":"invalid_client","error_description":"Bad client credentials"}
</code></pre>

<p>I guess I am not defining the <code>EGA_CLIENT_ID</code> variable correctly? I am using Snakemake 5.16 and Python 3.7.2. Thanks a lot in advance for your advice. </p>

<p>Code: </p>

<pre><code>import snakemake.remote.EGA as EGA

ega = EGA.RemoteProvider()
os.environ["EGA_USERNAME"] = "XXX"
os.environ["EGA_PASSWORD"] = "XXX"
os.environ["EGA_CLIENT_SECRET"] = "XXX"
os.environ["EGA_CLIENT_ID"] = "pyega3"
rule a:
  input:
      ega.remote("ega/EGAD00001002142/COLO_829_EPleasance_TGENPipe.bam.bai")
  output:
      "data/COLO_829BL_BCGSC_IlluminaPipe.bam.bai"
  shell:
      "cp {input} {output}"
</code></pre>

CC BY-SA 4.0
2020-05-05T16:18:36.783Z
"Bad client credentials" looks more like your username/password combination was not recognized. Do they match your EGA account?
mrhd
CC BY-SA 4.0
2020-05-05T16:20:32.100Z
Thanks for the comment - yes the match my account, I took them straight from the `CREDENTIALS_FILE` which I can successfully log in with when invoking `pyega3` from the command line.
ben
CC BY-SA 4.0
2020-05-05T16:24:21.007Z
Ok, that's good. Have you tried setting the environment variables before the line `ega = EGA.RemoteProvider`? Maybe the values are already used at this point?
mrhd
CC BY-SA 4.0
2020-05-05T16:26:08.187Z
Unfortunately changing the order results in the same error.
ben
<snakemake>
EGA remote download via snakemake fails due to EGA_CLIENT_ID specification
# EGA remote download via snakemake fails due to EGA_CLIENT_ID specification

(Asked by: username_0 on 2020-05-05)

The example code provided by the Snakemake documentation for remote downloading from the EGA archive fails for me. I have defined all required environment variables, but an error comes up stating 
{"error":"invalid_client","error_description":"Bad client credentials"}

I guess I am not defining the EGA_CLIENT_ID variable correctly? I am using Snakemake 5.16 and Python 3.7.2. Thanks a lot in advance for your advice. 
Code: 
import snakemake.remote.EGA as EGA

ega = EGA.RemoteProvider()
os.environ["EGA_USERNAME"] = "XXX"
os.environ["EGA_PASSWORD"] = "XXX"
os.environ["EGA_CLIENT_SECRET"] = "XXX"
os.environ["EGA_CLIENT_ID"] = "pyega3"
rule a:
  input:
      ega.remote("ega/EGAD00001002142/COLO_829_EPleasance_TGENPipe.bam.bai")
  output:
      "data/COLO_829BL_BCGSC_IlluminaPipe.bam.bai"
  shell:
      "cp {input} {output}"

**Tags:** snakemake
> **Comments:**
> **username_1**: "Bad client credentials" looks more like your username/password combination was not recognized. Do they match your EGA account?  
> **username_0**: Thanks for the comment - yes the match my account, I took them straight from the `CREDENTIALS_FILE` which I can successfully log in with when invoking `pyega3` from the command line.  
> **username_1**: Ok, that's good. Have you tried setting the environment variables before the line `ega = EGA.RemoteProvider`? Maybe the values are already used at this point?  
> **username_0**: Unfortunately changing the order results in the same error.  

---

## 1 answers

### Answer by username_0 on 2020-05-08. Score: 0 | Accepted answer

Okay, I finally solved it. The reason was the EGA_CLIENT_ID variable. In the pyega3.py script, there is a definition for the client_id for pyega3 v3.0.44 ("f20cd2d3-682a-4568-a53e-4262ef54c8f4"). After setting the EGA_CLIENT_ID to this value login was successful. 
os.environ["EGA_CLIENT_ID"] = "f20cd2d3-682a-4568-a53e-4262ef54c8f4"

I think this is a bug and I filed it on Snakemake's git repository - the official documentation just requires definition of the EGA_USERNAME and EGA_PASSWORD variables, and while definition of EGA_CLIENT_SECRET will probably need to be done by the user, the client ID should be pulled automatically from the pyega3 version installed locally. 
Of note, after successful login, the example download from the documentation failed with the following:
Missing input files for rule a:
ega/EGAD00001002142/COLO_829_EPleasance_TGENPipe.bam.bai

However, downloading files that I have access to worked, indicating that the paths to the files from the documentation are wrong or are access-protected.


---

