# Refreshed token, can't ping

**URL:** <https://discuss.pennylane.ai/t/refreshed-token-cant-ping/1943>\
**Category:** Strawberry Fields\
**Created:** [June 2, 2022, 12:00am UTC](https://discuss.pennylane.ai/t/refreshed-token-cant-ping/1943 "2022-06-02T00:00:08Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jack\_W](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/jack_w/32/965_2.png) [@Jack\_W](https://discuss.pennylane.ai/u/Jack_W)\
**Post date:** [June 2, 2022, 12:00am UTC](https://discuss.pennylane.ai/t/refreshed-token-cant-ping/1943/1 "2022-06-02T00:00:08Z")

</div>

Back again and confused again.  
After a month or two not accessing Xanadu, I programmatically refreshed the access token and on my Linux system the `~/.config/xanadu-cloud/.env` file was updated.  
But the `xcc.commands.ping()` test thereafter fails with

```python
$ python
Python 3.10.4 (main, Apr 2 2022, 09:04:19) [GCC 11.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import xcc.commands
>>> xcc.commands.ping()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/jwoehr/work/Xanadu/xanadu_venv/lib/python3.10/site-packages/xcc/commands.py", line 311, in ping
    connection.ping()
  File "/home/jwoehr/work/Xanadu/xanadu_venv/lib/python3.10/site-packages/xcc/connection.py", line 211, in ping
    return self.request(method="GET", path="/healthz")
  File "/home/jwoehr/work/Xanadu/xanadu_venv/lib/python3.10/site-packages/xcc/connection.py", line 241, in request
    self.update_access_token()
  File "/home/jwoehr/work/Xanadu/xanadu_venv/lib/python3.10/site-packages/xcc/connection.py", line 313, in update_access_token
    raise requests.exceptions.HTTPError(
requests.exceptions.HTTPError: Refresh token (e.g., Xanadu Cloud API key) is invalid
>>> 

```

---

<div class="post-metadata">

**Author:** ![Jack\_W](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/jack_w/32/965_2.png) [@Jack\_W](https://discuss.pennylane.ai/u/Jack_W)\
**Post date:** [June 2, 2022, 3:26am UTC](https://discuss.pennylane.ai/t/refreshed-token-cant-ping/1943/2 "2022-06-02T03:26:07Z")

</div>

I went to the cloud page, generated a new token, saved it programmatically. `ping()` and submitting jobs still doesn’t work.  
However, in the cloud page, it shows that I did generate the token and use it: " Your API key was created on **6/1/2022, 9:18:11 PM** and was last used on **6/1/2022, 9:18:11 PM** (from xxx.xxx.xxx.xxx)", i.e., a few moments ago.

---

<div class="post-metadata">

**Author:** ![CatalinaAlbornoz](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/catalinaalbornoz/32/1196_2.png) [@CatalinaAlbornoz](https://discuss.pennylane.ai/u/CatalinaAlbornoz)\
**Post date:** [June 2, 2022, 2:43pm UTC](https://discuss.pennylane.ai/t/refreshed-token-cant-ping/1943/3 "2022-06-02T14:43:19Z")

</div>

Hi @Jack_W,

Can you please confirm that you have the latest version of xcc (v0.2.1)?

Also, have you followed the steps [here](https://github.com/XanaduAI/xanadu-cloud-client#setup)?

---

<div class="post-metadata">

**Author:** ![Jack\_W](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/jack_w/32/965_2.png) [@Jack\_W](https://discuss.pennylane.ai/u/Jack_W)\
**Post date:** [June 2, 2022, 3:03pm UTC](https://discuss.pennylane.ai/t/refreshed-token-cant-ping/1943/4 "2022-06-02T15:03:31Z")

</div>

Hi @CatalinaAlbornoz …  
I have done this step:

```
import xcc
settings = xcc.Settings(REFRESH_TOKEN="Xanadu Cloud API key goes here")
settings.save() 

```

(of course substituting the API key I generated and copied from xanadu.ai). There is no error from that operation, and the file `$HOME/.config/xanadu-cloud/.env` is updated as a result of that operation.

Then:

```auto
$ xcc ping
ERROR: Refresh token (e.g., Xanadu Cloud API key) is invalid.

```

---

<div class="post-metadata">

**Author:** ![Jack\_W](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/jack_w/32/965_2.png) [@Jack\_W](https://discuss.pennylane.ai/u/Jack_W)\
**Post date:** [June 2, 2022, 3:05pm UTC](https://discuss.pennylane.ai/t/refreshed-token-cant-ping/1943/5 "2022-06-02T15:05:54Z")

</div>

I also made sure to update with `pip install strawberryfields --upgrade`

---

<div class="post-metadata">

**Author:** ![Jack\_W](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/jack_w/32/965_2.png) [@Jack\_W](https://discuss.pennylane.ai/u/Jack_W)\
**Post date:** [June 2, 2022, 3:17pm UTC](https://discuss.pennylane.ai/t/refreshed-token-cant-ping/1943/6 "2022-06-02T15:17:49Z")

</div>

```auto
$ xcc version
Xanadu Cloud Client version 0.2.1
```

---

<div class="post-metadata">

**Author:** ![Jack\_W](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/jack_w/32/965_2.png) [@Jack\_W](https://discuss.pennylane.ai/u/Jack_W)\
**Post date:** [June 2, 2022, 3:22pm UTC](https://discuss.pennylane.ai/t/refreshed-token-cant-ping/1943/7 "2022-06-02T15:22:16Z")

</div>

Hmm, I just tried this:  
`xcc config set REFRESH_TOKEN "....."`  
And now I can ping  
I guess somehow a bad character got in the way I did it programmatically in Python.

---

<div class="post-metadata">

**Author:** ![Jack\_W](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/jack_w/32/965_2.png) [@Jack\_W](https://discuss.pennylane.ai/u/Jack_W)\
**Post date:** [June 2, 2022, 3:31pm UTC](https://discuss.pennylane.ai/t/refreshed-token-cant-ping/1943/8 "2022-06-02T15:31:55Z")

</div>

Weird, I’m playing with this, and I am reasonably sure I am feeding the same string in to my Python refresh token code as I do at the xcc command line, and yet the command line work and the Python program does not work. Both successfully alter the config file, but afterwards, only the xcc command line alteration generates a useful token.

---

<div class="post-metadata">

**Author:** ![Jack\_W](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/jack_w/32/965_2.png) [@Jack\_W](https://discuss.pennylane.ai/u/Jack_W)\
**Post date:** [June 2, 2022, 3:35pm UTC](https://discuss.pennylane.ai/t/refreshed-token-cant-ping/1943/9 "2022-06-02T15:35:04Z")

</div>

Found it. There was indeed a superfluous lf (0x0a) in the string I was feeding to my Python code. Sheesh. Apologies for ringing the bell!

---

<div class="post-metadata">

**Author:** ![CatalinaAlbornoz](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/catalinaalbornoz/32/1196_2.png) [@CatalinaAlbornoz](https://discuss.pennylane.ai/u/CatalinaAlbornoz)\
**Post date:** [June 2, 2022, 6:44pm UTC](https://discuss.pennylane.ai/t/refreshed-token-cant-ping/1943/10 "2022-06-02T18:44:10Z")

</div>

I’m glad you found the problem @Jack_W!
