# Issue with decoding Base 64

**URL:** <https://community.hubspot.com/t/issue-with-decoding-base-64/84101>\
**Category:** CMS Development\
**Created:** [June 26, 2023, 1:23pm UTC](https://community.hubspot.com/t/issue-with-decoding-base-64/84101 "2023-06-26T13:23:22Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![SStrachan1](https://avatars.discourse-cdn.com/v4/letter/s/aca169/32.png) [@SStrachan1](https://community.hubspot.com/u/SStrachan1)\
**Post date:** [June 26, 2023, 1:23pm UTC](https://community.hubspot.com/t/issue-with-decoding-base-64/84101/1 "2023-06-26T13:23:22Z")

</div>

I am getting an error in Hubspot while trying to decode a URL. I get the feeling this is just an issue with the Hubsopt code validator.

```lia-code-sample
{% set encoded_url = request.query %}
<h5>encoded: {{ encoded_url }}</h5>

{% set decoded_url = encoded_url|b64decode %}
<h5>decoded: {{ decoded_url }}</h5>

```

On the decode part, I get the following error and can’t publish the module.  
“input byte array has wrong 4-byte ending unit”  
The test below works which is essentially doing the same thing.

```lia-code-sample
{% set myurl = 'yacht=485982377&status=charter&currency=USD&poa=no&vat_paid=no&broker=453230516&branded=yes&event=YACHT-SHOW' %}
{% set encoded_url = myurl|b64encode %} 
<h3>encoded: {{ encoded_url }}</h3>

{% set decoded_url = encoded_url|b64decode %}
<h3>decoded: {{ decoded_url }}</h3>

```

I need to be able to store the URL in a variable and decode it. Any ideas on what to do?

---

<div class="post-metadata">

**Author:** ![MBERARD](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/mberard/32/61390_2.png) [@MBERARD](https://community.hubspot.com/u/MBERARD)\
**Post date:** [June 26, 2023, 2:58pm UTC](https://community.hubspot.com/t/issue-with-decoding-base-64/84101/2 "2023-06-26T14:58:27Z")

</div>

Hi @SStrachan1

I presume that the value of _request.query_ is already encoded in base64. For me, as you’re working with dynamical values hubspot validator is displaying an error because is unable to know that _request.query_ contains encoded values.

I’ll do it in a different way. In your template, define the following variable:

`{% set decoded_url = encoded_url is none ? "" : encoded_url|b64decode %}`

In your page, in the advanced section in the settings place the following declaration in the head rich\_text:

`{% set encoded_url = request.query %}`

That should solve your problem but it also could be a little forbidding if you have a lot of pages.

Have a nice day!

Matthieu

---

<div class="post-metadata">

**Author:** ![SStrachan1](https://avatars.discourse-cdn.com/v4/letter/s/aca169/32.png) [@SStrachan1](https://community.hubspot.com/u/SStrachan1)\
**Post date:** [June 26, 2023, 3:05pm UTC](https://community.hubspot.com/t/issue-with-decoding-base-64/84101/3 "2023-06-26T15:05:36Z")

</div>

Hey @MBERARD Thanks for the reply.  
I am still getting the same “input byte array has wrong 4-byte ending unit” error with this code:

`{% set decoded_url = encoded_url is none ? "" : encoded_url|b64decode %}`

---

<div class="post-metadata">

**Author:** ![MBERARD](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/mberard/32/61390_2.png) [@MBERARD](https://community.hubspot.com/u/MBERARD)\
**Post date:** [June 26, 2023, 3:11pm UTC](https://community.hubspot.com/t/issue-with-decoding-base-64/84101/4 "2023-06-26T15:11:48Z")

</div>

Can you please pprint _encoded\_url_ and post the results?

---

<div class="post-metadata">

**Author:** ![SStrachan1](https://avatars.discourse-cdn.com/v4/letter/s/aca169/32.png) [@SStrachan1](https://community.hubspot.com/u/SStrachan1)\
**Post date:** [June 26, 2023, 3:14pm UTC](https://community.hubspot.com/t/issue-with-decoding-base-64/84101/5 "2023-06-26T15:14:13Z")

</div>

Here you go.

`(String: eWFjaHQ9NDg1OTgyMzc3JnN0YXR1cz1jaGFydGVyJmN1cnJlbmN5PVVTRCZwb2E9bm8mdmF0X3BhaWQ9bm8mYnJva2VyPTQ1MzIzMDUxNiZicmFuZGVkPXllcyZldmVudD1ZQUNIVC1TSE9X=)`

I believe the = at the end is being added automatically.

---

<div class="post-metadata">

**Author:** ![MBERARD](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/mberard/32/61390_2.png) [@MBERARD](https://community.hubspot.com/u/MBERARD)\
**Post date:** [June 26, 2023, 3:36pm UTC](https://community.hubspot.com/t/issue-with-decoding-base-64/84101/6 "2023-06-26T15:36:07Z")

</div>

I think you find the problem. If you encode in base64 your query:

`yacht=485982377&status=charter&currency=USD&poa=no&vat_paid=no&broker=453230516&branded=yes&event=YACHT-SHOW`

You get the following results:

`eWFjaHQ9NDg1OTgyMzc3JnN0YXR1cz1jaGFydGVyJmN1cnJlbmN5PVVTRCZwb2E9bm8mdmF0X3BhaWQ9bm8mYnJva2VyPTQ1MzIzMDUxNiZicmFuZGVkPXllcyZldmVudD1ZQUNIVC1TSE9X`

So it’s probably an interpretation of your browser as he consider the encoded query as a key instead of the whole value. You should probably update your URL with the following structure:

`https://www.your-current-url.com/page?q=eWFjaHQ9NDg1OTgyMzc3JnN0YXR1cz1jaGFydGVyJmN1cnJlbmN5PVVTRCZwb2E9bm8mdmF0X3BhaWQ9bm8mYnJva2VyPTQ1MzIzMDUxNiZicmFuZGVkPXllcyZldmVudD1ZQUNIVC1TSE9X`

Then update your code with the following declaration:

`{% set encoded_url = request.query_dict.q %}`

---

<div class="post-metadata">

**Author:** ![SStrachan1](https://avatars.discourse-cdn.com/v4/letter/s/aca169/32.png) [@SStrachan1](https://community.hubspot.com/u/SStrachan1)\
**Post date:** [June 26, 2023, 4:30pm UTC](https://community.hubspot.com/t/issue-with-decoding-base-64/84101/7 "2023-06-26T16:30:50Z")

</div>

That did the trick. I had that earlier, but no this:

`{% set decoded_url = encoded_url is none ? "" : encoded_url|b64decode %}`

That is what was needed. Thank you for your halp!
