Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Permission denied" em arquivo temporário durante resolução do captcha #20

Open
ivanlonel opened this issue Nov 30, 2023 · 5 comments
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@ivanlonel
Copy link

ivanlonel commented Nov 30, 2023

Estou recebendo o seguinte erro nessa linha quando chamo download_country, download_state etc:

Traceback (most recent call last):
  File "d:\ivanl\git\car\car.py", line 6, in <module>
    car.download_country()
  File "D:\ivanl\git\car\.venv\Lib\site-packages\SICAR\sicar.py", line 501, in download_country
    result[str(state)] = self.download_state(
                         ^^^^^^^^^^^^^^^^^^^^
  File "D:\ivanl\git\car\.venv\Lib\site-packages\SICAR\sicar.py", line 464, in download_state
    return self.download_cities(
           ^^^^^^^^^^^^^^^^^^^^^
  File "D:\ivanl\git\car\.venv\Lib\site-packages\SICAR\sicar.py", line 427, in download_cities
    result[(city, code)] = self.download_city_code(
                           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\ivanl\git\car\.venv\Lib\site-packages\SICAR\sicar.py", line 361, in download_city_code
    captcha = self._driver.get_captcha(self._download_captcha())
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\ivanl\git\car\.venv\Lib\site-packages\SICAR\drivers\tesseract.py", line 64, in get_captcha
    self._process_captcha(captcha),
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\ivanl\git\car\.venv\Lib\site-packages\SICAR\drivers\captcha.py", line 110, in _process_captcha
    cv2.cvtColor(self._png_to_jpg(captcha), cv2.COLOR_BGR2GRAY)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\ivanl\git\car\.venv\Lib\site-packages\SICAR\drivers\captcha.py", line 63, in _png_to_jpg
    captcha.save(png.name)
  File "D:\ivanl\git\car\.venv\Lib\site-packages\PIL\Image.py", line 2435, in save
    fp = builtins.open(filename, "w+b")
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
PermissionError: [Errno 13] Permission denied: 'C:\\Users\\ivanl\\AppData\\Local\\Temp\\tmpoyd5af69.png'

Parece que o pillow está chamando open() no arquivo que já foi aberto pelo NamedTemporaryFile, assim como nesse caso: https://stackoverflow.com/questions/23212435/permission-denied-to-write-to-my-temporary-file

Copy link

Welcome! Your issue will be analyzed as soon as possible. Hopefully, we can find a solution to the problem together, please try to provide as much information as possible to help us identify and fix the bug or improve the repository.

@urbanogilson urbanogilson added the bug Something isn't working label Jan 16, 2024
@urbanogilson
Copy link
Owner

O problema persiste?

Qual é a versão do sistema operacional? Python?

@urbanogilson urbanogilson added the help wanted Extra attention is needed label Jan 18, 2024
@ivanlonel
Copy link
Author

Bom dia.

Sim, o problema persiste na versão 0.7.0.

Windows 11 Pro, 22H2 (22621.3007)

Python 3.11.5
Saída de sys.version:
3.11.5 (tags/v3.11.5:cce6ba9, Aug 24 2023, 14:38:34) [MSC v.1936 64 bit (AMD64)]

pillow 10.2.0

@ivanlonel ivanlonel removed their assignment Feb 4, 2024
@rmatias3
Copy link

Mesmo problema comigo. Instalei o módulo agora. Ou seja, a versão mais recente. E estou com o python 3.12.4.

Traceback (most recent call last):
File "c:\Users\RSMat\OneDrive\Engenharia\W2 Engenharia\Rio Vivo\SICAR\Programação\sicar_access.py", line 12, in
result = car.download_state(state=State.AL, polygon=Polygon.AREA_PROPERTY, folder='AL')
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\RSMat\AppData\Local\Programs\Python\Python312\Lib\site-packages\SICAR\sicar.py", line 292, in download_state
captcha = self._driver.get_captcha(self._download_captcha())
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\RSMat\AppData\Local\Programs\Python\Python312\Lib\site-packages\SICAR\drivers\tesseract.py", line 64, in get_captcha
self._process_captcha(captcha),
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\RSMat\AppData\Local\Programs\Python\Python312\Lib\site-packages\SICAR\drivers\captcha.py", line 110, in _process_captcha
cv2.cvtColor(self._png_to_jpg(captcha), cv2.COLOR_BGR2GRAY)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\RSMat\AppData\Local\Programs\Python\Python312\Lib\site-packages\SICAR\drivers\captcha.py", line 63, in _png_to_jpg
captcha.save(png.name)
File "C:\Users\RSMat\AppData\Local\Programs\Python\Python312\Lib\site-packages\PIL\Image.py", line 2564, in save
fp = builtins.open(filename, "w+b")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
PermissionError: [Errno 13] Permission denied: 'C:\Users\RSMat\AppData\Local\Temp\tmpktsks7yh.png'

@brittoeduardo
Copy link

Eu consegui fazendo essas seguintes alterações:

1 - Entre na biblioteca do SICAR e depois captcha.py
2 - Dentro do captcha.py localize as duas linhas

    with tempfile.NamedTemporaryFile(suffix=".png") as png:
        with tempfile.NamedTemporaryFile(suffix=".jpg") as jpg:

3 - Adicione o comando delete=False

    with tempfile.NamedTemporaryFile(suffix=".png",delete=False) as png:
        with tempfile.NamedTemporaryFile(suffix=".jpg",delete=False) as jpg:

4 - Salve o arquivo captcha.py .

Talvez resolva de forma provisória.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

4 participants