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

Making PyCall for os.urandom results in "base64 binary data" #685

Closed
FinlayDaG33k opened this issue Apr 30, 2019 · 2 comments
Closed

Making PyCall for os.urandom results in "base64 binary data" #685

FinlayDaG33k opened this issue Apr 30, 2019 · 2 comments

Comments

@FinlayDaG33k
Copy link

Hii there,

I'm trying to get the os.urandom method from Python to work in my Julia script.
However, all I can get from it is a base64 binary data:

salt = os.urandom(floor(Int, salt_length / 2));
println(salt);

base64 binary data: 2pzXfwq2qPAOCg==

I wonder if this is a bug or intended behaviour and how one could fix this as it's nowhere in the documentation.

@FinlayDaG33k
Copy link
Author

Found that I can do this using the the Julia Random library instead...
Closing

@stevengj
Copy link
Member

It works fine for me, though it is returning a String which is probably not what you want in Julia. If you want a Vector{UInt8} (i.e. a vector of bytes), you can do:

julia> pycall(pyimport("os").urandom, Vector{UInt8}, 10)
10-element Array{UInt8,1}:
 0xeb
 0x4b
 0x12
 0x69
 0xf6
 0x78
 0x56
 0x22
 0x7a
 0x8b

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