So this is my code, which throws a MemoryError at line 2 with no other details.
import base64
b = bytes(2108292477256562115)
print(base64.urlsafe_b64encode(b))
bytes(2108292477256562115) is a byte string with length 2108292477256562115. If you want to convert that integer to a minimal number of bytes, you need to get the number of bytes required to represent it first:
n = 2108292477256562115
byte_length = (n.bit_length() + 7) // 8
then convert:
n.to_bytes(byte_length, 'big')
b = b'2108292477256562115'orb = str(n).encode().