0

Following code works in Python2 but not in Python3?

import http.client
from io import StringIO
    
if __name__ == '__main__':
   res=http.client.HTTPMessage(StringIO(u"headers"))
   print(str(res))

[]$ python3 test.py
Traceback (most recent call last):
  File "test.py", line 9, in <module>
    print(str(res))
  File "/usr/lib64/python3.9/email/message.py", line 135, in __str__
    return self.as_string()
  File "/usr/lib64/python3.9/email/message.py", line 158, in as_string
    g.flatten(self, unixfrom=unixfrom)
  File "/usr/lib64/python3.9/email/generator.py", line 97, in flatten
    policy = policy.clone(max_line_length=self.maxheaderlen)
AttributeError: '_io.StringIO' object has no attribute 'clone'

I'm currently porting old Python2 code over to Python3. This is a dummy test of a problem I run into.

  • 1
    Does this answer your question? [StringIO in Python3](https://stackoverflow.com/questions/11914472/stringio-in-python3) – itprorh66 May 07 '21 at 19:47
  • No, that is an issue of importing StringIO. In this case is the missing 'clone' which is not present in 'Python3' but in 'Python2'. – Phil W. Gum May 09 '21 at 08:31

0 Answers0