Get Inspire insights from former attendees in our AMA discussion thread on Inspire Buzz. ACEs and other community members are on call all week to answer!

Alteryx Designer Desktop Discussions

Find answers, ask questions, and share expertise about Alteryx Designer Desktop and Intelligence Suite.

Python - base64 decoder

AndrewCrayford
8 - Asteroid

I found this piece of Pyhton code on the internet, Which decodes the base64 into uft-8

 

import base64

encodedStr = "0K3RgtC+INCw0LLRgtC+0LzQsNGC0LjRh9C10YHQutCw0Y8g0YDQsNGB0YHRi9C70LrQsC4="

# Url Safe Base64 Decoding
decodedBytes = base64.urlsafe_b64decode(encodedStr)
decodedStr = str(decodedBytes, "utf-8")

print(decodedStr)

 

When I run it in the Pyhton tool it works and display the decode in phyton. I was wondering how do I output it to the workflow so I can used other tools on it?

How can I chanege the Encoded Str so it reading from a set field or event from a file?

3 REPLIES 3
BrandonB
Alteryx
Alteryx

The Python tool in Alteryx can read in a data frame from earlier in the workflow by using the Alteryx.read("#1") function. If your encodedStr exists upstream in your workflow, you could pass this in using that function and then leverage the value in your script. 

AndrewCrayford
8 - Asteroid

I not used Python tool before so i not sure about the commands or how it needs to write in Python to make it work. Once import the string into Python how do i make it display on the screen and with the eariler Python how do I amend it so it looks for the field instead of it hardcoded into the code?

 

 

AndrewCrayford
8 - Asteroid

This is the code i am trying to use

 

#################################
# List all non-standard packages to be imported by your
# script here (only missing packages will be installed)
from ayx import Package
#Package.installPackages(['pandas','numpy'])


#################################
from ayx import Alteryx


#################################
data = Alteryx.read("#1")


#################################
data


#################################
import base64

encodedStr = data

# Standard Base64 Decoding
decodedBytes = base64.b64decode(encodedStr)
decodedStr = str(decodedBytes, "utf-8")

Alteryx.write(decodedStr,4)


#################################

 

 

But it given me the following errrors

 

Error: Python (15): ---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-5-b10eef4cdde5> in <module>
4
5 # Standard Base64 Decoding
----> 6 decodedBytes = base64.b64decode(encodedStr)
7 decodedStr = str(decodedBytes, "utf-8")
8
c:\program files\alteryx\bin\miniconda3\envs\jupytertool_venv\lib\base64.py in b64decode(s, altchars, validate)
78 in the input result in a binascii.Error.
79 """
---> 80 s = _bytes_from_decode_data(s)
81 if altchars is not None:
82 altchars = _bytes_from_decode_data(altchars)
c:\program files\alteryx\bin\miniconda3\envs\jupytertool_venv\lib\base64.py in _bytes_from_decode_data(s)
44 except TypeError:
45 raise TypeError("argument should be a bytes-like object or ASCII "
---> 46 "string, not %r" % s.__class__.__name__) from None
47
48
TypeError: argument should be a bytes-like object or ASCII string, not 'DataFrame'



Can anyone help me to fix this or to explain when I need to do in order to get this to work?

Labels