String modifying error, trying to delete data in string

Steven D'Aprano steve+comp.lang.python at pearwood.info
Mon Mar 24 13:09:11 EDT 2014


On Mon, 24 Mar 2014 09:20:26 -0700, mikie wrote:

> Im trying to delete some headers in the request but get an error saying:
> 'str' object has no attribute 'pop'

What sort of object is data? What do you expect it to be, and what it is 
actually?

Given that you are calling data.pop("Proxy-Connection"), that suggests to 
me that you think data is a dict. The error message given tells you that 
data is a str.

> How can I modify data received from the client?

The same as any string: make a copy with whatever modifications you want. 
Strings have a replace method; you can use the re module to use regexes; 
you can slice them with some_string[start:end] syntax, etc. But it looks 
to me like you might be better off using a higher-level protocol rather 
than using socket. What sort of data are you expecting back?



-- 
Steven D'Aprano
http://import-that.dreamwidth.org/



More information about the Python-list mailing list