0

        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.

1
  • Looking at documentation for how to raise Exceptions in python 3 (docs.python.org/3.7/reference/…) as compared to python 2 (docs.python.org/2.7/reference/…) you can how the specification has changed. There will be many such changes necessary and tools such as 2to3 as suggested by @Mark can go a long way to making this transition easier. Commented Mar 6, 2019 at 4:29

1 Answer 1

1

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)
Sign up to request clarification or add additional context in comments.

5 Comments

Sorry I am not good at converting python2 to python3 code can you convert this as well? raise ValueError, "unknown url type: %s" % self.__original ^ SyntaxError: invalid syntax
@John Why not run the 2to3 script to port your code? The link is in my answer. In that case it is just raise ValueError("unknown url type: %s" % self.__original").
thank you, Does 2to3 automatically do this? Or do I have to go in and make the changes?
@John Yes, read the documentation.
Sorry I went ahead and read through the documentation. I am having another error it's saying I am missing the module mimetools

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.