question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

There is a problem with python 3.8 and escape sequence:

See original GitHub issue

There is a problem with python 3.8 and escape sequence: 'invalid escape sequence \*

________________________ ERROR collecting test session _________________________
/opt/virtualenvs/py38/lib/python3.8/site-packages/py/_path/common.py:383: in visit
    for x in Visitor(fil, rec, ignore, bf, sort).gen(self):
/opt/virtualenvs/py38/lib/python3.8/site-packages/py/_path/common.py:435: in gen
    for p in self.gen(subdir):
/opt/virtualenvs/py38/lib/python3.8/site-packages/py/_path/common.py:435: in gen
    for p in self.gen(subdir):
/opt/virtualenvs/py38/lib/python3.8/site-packages/py/_path/common.py:424: in gen
    dirs = self.optsort([p for p in entries
/opt/virtualenvs/py38/lib/python3.8/site-packages/py/_path/common.py:425: in <listcomp>
    if p.check(dir=1) and (rec is None or rec(p))])
/opt/virtualenvs/py38/lib/python3.8/site-packages/_pytest/main.py:667: in _recurse
    ihook = self.gethookproxy(dirpath)
/opt/virtualenvs/py38/lib/python3.8/site-packages/_pytest/main.py:482: in gethookproxy
    my_conftestmodules = pm._getconftestmodules(fspath)
/opt/virtualenvs/py38/lib/python3.8/site-packages/_pytest/config/__init__.py:431: in _getconftestmodules
    mod = self._importconftest(conftestpath.realpath())
/opt/virtualenvs/py38/lib/python3.8/site-packages/_pytest/config/__init__.py:470: in _importconftest
    raise ConftestImportFailure(conftestpath, sys.exc_info())
E   _pytest.config.ConftestImportFailure: (local('/conftest.py'), (<class 'SyntaxError'>, SyntaxError('invalid escape sequence \\*', ('/opt/virtualenvs/py38/lib/python3.8/site-packages/requests_oauthlib/oauth1_session.py', 258, 9, '        """Fetch a request token.\n')), <traceback object at 0x7fee844d6140>))

_Originally posted by @matejsp in https://github.com/requests/requests-oauthlib/issues/443#issuecomment-954664334_

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
jtroussardcommented, Jan 2, 2022

This doc string is flagged as a raw string, and that seems to be the fix for this warning. See stackoverflow link…

def fetch_request_token(self, url, realm=None, **request_kwargs):
        r"""Fetch a request token.

        This is the first step in the OAuth 1 workflow. A request token is
        obtained by making a signed post request to url. The token is then
        parsed from the application/x-www-form-urlencoded response and ready
        to be used to construct an authorization url.

        :param url: The request token endpoint URL.
        :param realm: A list of realms to request access to.
        :param \*\*request_kwargs: Optional arguments passed to ''post''
        ..."""

https://stackoverflow.com/questions/52335970/how-to-fix-string-deprecationwarning-invalid-escape-sequence-in-python

and more insight into this patch https://bugs.python.org/issue27364

I think we are safe to say that this issue has been covered.

1reaction
matejspcommented, Jan 2, 2022

Trying with sample test.py and current python that I use. It is not the same but similar behaviour.

test.py

def test_me():
    """ some \*\* """ 
    print("ok")

pytest test.py

(env39) ➜  ~ pytest test.py
=============================================================================================================== test session starts ================================================================================================================
platform darwin -- Python 3.9.9, pytest-4.6.11, py-1.10.0, pluggy-0.13.1
Using --random-order-bucket=module
Using --random-order-seed=93520

rootdir: /Users/user
plugins: freezegun-0.4.2, mock-1.11.2, metadata-1.10.0, random-order-0.8.1+bts1, celery-4.4.7, cov-2.11.1, django-3.10.0, html-1.22.1, forked-1.3.0, xdist-1.27.0
collected 1 item                                                                                                                                                                                                                                   

test.py .                                                                                                                                                                                                                                    [100%]

================================================================================================================= warnings summary =================================================================================================================
test.py:2
  /Users/user/test.py:2: DeprecationWarning: invalid escape sequence \*
    """ some \*\* """

-- Docs: https://docs.pytest.org/en/latest/warnings.html
======================================================================================================= 1 passed, 1 warnings in 0.06 seconds =======================================================================================================
(env39) ➜  ~ 
Read more comments on GitHub >

github_iconTop Results From Across the Web

Mailman 3 What to do about invalid escape sequences
The thing that the python escape sequences is complaining about are never invalid (As was pointed out, it's complaining when a sequence of...
Read more >
Escape sequences in Python strings - LWN.net
The main problem that warning for illegal escape sequences is trying to solve is for file names on Windows systems, where the backslash...
Read more >
SyntaxError: invalid escape sequence · Issue #294 - GitHub
With Python 3.7 there is an issue with invalid escape characters (see error message below). from pyppeteer.us_keyboard_layout import keyDefinitions
Read more >
invalid escape sequence" in Python? - Stack Overflow
If your backslash sequence does accidentally match one of Python's escape sequences, but you didn't mean it to, that's even worse.
Read more >
Python Escape Characters - W3Schools
An escape character is a backslash \ followed by the character you want to insert. ... Try it Yourself ». To fix this...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found