简体   繁体   中英

running python3, using python2 code, I changed httplib to http.client, ERROR

  if attr[:12] == '_Request__r_': name = attr[12:] if hasattr(Request, 'get_' + name): getattr(self, 'get_' + name)() return getattr(self, attr) raise AttributeError, attr def get_method(self): if self.has_data(): return "POST" else: return "GET" 

  raise AttributeError, attr ^ SyntaxError: invalid syntax 

How do I fix this error? As you can see above I have added the lines of code giving me an error.

Per the 2to3 documentation :

raise Converts raise E, V to raise E(V), and raise E, V, T to raise E(V).with_traceback(T). If E is a tuple, the translation will be incorrect because substituting tuples for exceptions has been removed in Python 3.

So it should be:

raise AttributeError(attr)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM