代码之家  ›  专栏  ›  技术社区  ›  Nouman ProfHase85

使用Binascii[duplicate]的Hexlify输入

  •  2
  • Nouman ProfHase85  · 技术社区  · 8 年前

    我正在努力 hexlify

    TypeError: a bytes-like object is required, not 'str'
    

    b 在string之前,它可以工作,但是我如何使用输入呢?

    import binascii as bs
    text = input('Please Enter Your text:')
    bs.hexlify(text)
    

    我试着做:

    text = input('Please enter you text:')
    import binascii as bs
    bs.hexlify(bytes(text))
    

    但它会产生以下错误:

    TypeError: string argument without an encoding
    

    1 回复  |  直到 8 年前
        1
  •  4
  •   Dor-Ron    8 年前

    将编码参数添加到 bytes

    import binascii as bs
    text = input('Please Enter Your text:')
    bs.hexlify(bytes(text, encoding="utf8"))
    
    推荐文章