相关疑难解决方法(0)

TypeError:'str'不支持缓冲区接口

plaintext = input("Please enter the text you want to compress")
filename = input("Please enter the desired filename")
with gzip.open(filename + ".gz", "wb") as outfile:
    outfile.write(plaintext) 
Run Code Online (Sandbox Code Playgroud)

上面的python代码给出了以下错误:

Traceback (most recent call last):
  File "C:/Users/Ankur Gupta/Desktop/Python_works/gzip_work1.py", line 33, in <module>
    compress_string()
  File "C:/Users/Ankur Gupta/Desktop/Python_works/gzip_work1.py", line 15, in compress_string
    outfile.write(plaintext)
  File "C:\Python32\lib\gzip.py", line 312, in write
    self.crc = zlib.crc32(data, self.crc) & 0xffffffff
TypeError: 'str' does not support the buffer interface
Run Code Online (Sandbox Code Playgroud)

python string gzip

263
推荐指数
5
解决办法
33万
查看次数

在Python中使用套接字发送字典?

我的问题:好的,我做了一个小聊天程序,我基本上使用套接字来通过网络发送消息.

它工作得很好,但当我决定更进一步时,我遇到了一个问题.

我决定在我通过网络发送的字符串中添加一些加密,所以我继续编写了执行该操作的脚本.

问题是,显然你不能像通过字符串一样通过套接字发送字典.

我先做了一些研究,然后我找到了关于泡菜的东西.不幸的是,除了将字典导出到文件之外,我无法确切地知道如何使用它们来转换字符串,但是如果不更改我的程序,我就无法做到这一点.

任何人都可以帮助解释我是如何做到这一点的吗?我到处都看了看,但我似乎无法弄清楚如何.

我已经上传了迄今为止我所拥有的内容,如果有任何人感兴趣的话.

print("\n\t\t Fill out the following fields:")
HOST = input("\nNet Send Server Public IP: ")
PORT = int(input("\nNet Send Server Port: "))
#------------------------------------------------
#Assessing Validity of Connection
#------------------------------------------------
try:
    s = socket(AF_INET,SOCK_STREAM)
    s.connect((HOST,PORT))
    print("Connected to server:",HOST,)
except IOError:
    print("\n\n\a\t\tUndefined Connection Error Encountered")
    input("Press Enter to exit, then restart the script")
    sys.exit()
#-------------------------------------------------
#Now Sending and recieving mesages
#-------------------------------------------------


i = True
while i is True:
    try:
        User_input = input("\n Enter your message: ")
    Lower_Case_Conversion …
Run Code Online (Sandbox Code Playgroud)

python sockets dictionary translation

7
推荐指数
2
解决办法
3万
查看次数

标签 统计

python ×2

dictionary ×1

gzip ×1

sockets ×1

string ×1

translation ×1