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.

`portalocker` error: FileNotFoundError: [Errno 2] No such file or directory

See original GitHub issue

This is autogenerated. Please review and update as needed.

Describe the bug

Command Name az account get-access-token

Errors:

The command failed with an unexpected error. Here is the traceback:
[Errno 2] No such file or directory
Traceback (most recent call last):
  File "/opt/az/lib/python3.6/site-packages/knack/cli.py", line 231, in invoke
    cmd_result = self.invocation.execute(args)
  File "/opt/az/lib/python3.6/site-packages/azure/cli/core/commands/__init__.py", line 657, in execute
    raise ex
  File "/opt/az/lib/python3.6/site-packages/azure/cli/core/commands/__init__.py", line 720, in _run_jobs_serially
    results.append(self._run_job(expanded_arg, cmd_copy))
  File "/opt/az/lib/python3.6/site-packages/azure/cli/core/commands/__init__.py", line 691, in _run_job
    result = cmd_copy(params)
  File "/opt/az/lib/python3.6/site-packages/azure/cli/core/commands/__init__.py", line 328, in __call__
    return self.handler(*args, **kwargs)
  File "/opt/az/lib/python3.6/site-packages/azure/cli/core/commands/command_operation.py", line 121, in handler
    return op(**command_args)
  File "/opt/az/lib/python3.6/site-packages/azure/cli/command_modules/profile/custom.py", line 75, in get_access_token
    tenant=tenant)
  File "/opt/az/lib/python3.6/site-packages/azure/cli/core/_profile.py", line 381, in get_raw_token
    credential = self._create_credential(account, tenant)
  File "/opt/az/lib/python3.6/site-packages/azure/cli/core/_profile.py", line 588, in _create_credential
    return identity.get_user_credential(username_or_sp_id)
  File "/opt/az/lib/python3.6/site-packages/azure/cli/core/auth/identity.py", line 182, in get_user_credential
    return UserCredential(self.client_id, username, **self._msal_app_kwargs)
  File "/opt/az/lib/python3.6/site-packages/azure/cli/core/auth/msal_authentication.py", line 41, in __init__
    accounts = self.get_accounts(username)
  File "/opt/az/lib/python3.6/site-packages/msal/application.py", line 872, in get_accounts
    accounts = self._find_msal_accounts(environment=self.authority.instance)
  File "/opt/az/lib/python3.6/site-packages/msal/application.py", line 912, in _find_msal_accounts
    query={"environment": environment})
  File "/opt/az/lib/python3.6/site-packages/msal_extensions/token_cache.py", line 53, in find
    with CrossPlatLock(self._lock_location):
  File "/opt/az/lib/python3.6/site-packages/msal_extensions/cache_lock.py", line 29, in __enter__
    file_handle = self._lock.__enter__()
  File "/opt/az/lib/python3.6/site-packages/portalocker/utils.py", line 199, in __enter__
    return self.acquire()
  File "/opt/az/lib/python3.6/site-packages/portalocker/utils.py", line 161, in acquire
    fh = self._prepare_fh(fh)
  File "/opt/az/lib/python3.6/site-packages/portalocker/utils.py", line 194, in _prepare_fh
    fh.truncate(0)
FileNotFoundError: [Errno 2] No such file or directory

To Reproduce:

Steps to reproduce the behavior. Note that argument values have been redacted, as they may contain sensitive information.

  • Put any pre-requisite steps here…
  • az account get-access-token --resource {} --subscription {} -o={}

Expected Behavior

Environment Summary

Linux-5.10.16.3-microsoft-standard-WSL2-x86_64-with-debian-bullseye-sid, Ubuntu 20.04.3 LTS
Python 3.6.10
Installer: DEB

azure-cli 2.30.0

Extensions:
azure-devops 0.20.0

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:22 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
jiaslicommented, Dec 13, 2021

Moving to a new issue #20707.

1reaction
wolphcommented, Nov 11, 2021

In terms of portalocker, it seems there would be no downside if we put that truncate(0) into the retry logic?

There’s no real downside, the only “downside” I see is that it could hide these errors. This scenario should not occur so I do believe it should warrant a warning that your lock might not be valid anymore.

Once the lockfile has disappeared, your lock has disappeared as well and anyone else could lock in the mean time.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Python FileNotFoundError: [Errno 2] No such file or directory ...
This error tells you that you are trying to access a file or folder that does not exist. To fix this error, check...
Read more >
how to solve python ilock FileNotFoundError? - Stack Overflow
I'm seeing the same error. Looks to me like it's a bug in the ilock library. In short, when two ILock objects are...
Read more >
error: could not install packages due to an oserror: [errno 2] no ...
I use the latest version of python and pip. ERROR: Could not install packages due to an OSError: [Errno 2] No such file...
Read more >
portalocker - PyPI
Portalocker is a library to provide an easy API to file locking. An important detail to note is that on Linux and Unix...
Read more >
Filenotfounderror errno 2 no such file or directory python error ...
How to solve filenotfounderror errno 2 no such file or directory in python is shown.
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