const decodeCert = Uint8Array.from(window.atob(cert), value => value.charCodeAt(0));…
- User
const decodeCert = Uint8Array.from(window.atob(cert), value => value.charCodeAt(0));
What would be python eqiuvalent
- Assistant
To accomplish the same thing in Python—decoding a base64 string to a byte array (which is what
Uint8Array.from(window.atob(cert), value => value.charCodeAt(0))does in JavaScript)—you can use Python's built-inbase64module. This module enables you to decode a base64 encoded string directly to bytes, which is the Python equivalent of JavaScript's Uint8Array.Here is how you can do it:
import base64 # Assuming 'cert' is your base64 encoded string cert = "your_base64_encoded_string_here" # Decode the base64 string to bytes decoded_cert = base64.b64decode(cert) # 'decoded_cert' is now a bytes object, which is the Python equivalent of JavaScript's Uint8ArrayIn this code,
certis assumed to be a base64 encoded string that you want to decode. The functionbase64.b64decode()decodes this string into bytes, which is essentially what you are looking for as the Python equivalent of the given JavaScript code. - User
what does this do. How to redo this in python:
async [localTypes.CREATE_CERTIFICATE]({ state, dispatch }, user) { const { data: { password, cert_body: cert } } = await authApi.getCertificate(user.id); const decodeCert = Uint8Array.from(window.atob(cert), value => value.charCodeAt(0)); const link = document.createElement('a'); const username = utl.codingAndDecodingStr(state.username || '');
link.href = window.URL.createObjectURL(new Blob([decodeCert])); link.download = `${username || 'cert'}_${user.username}.p12`; document.body.appendChild(link); link.click(); document.body.removeChild(link); await dispatch(localTypes.FETCH_USERS); return password;},
- Assistant