emissions-api / sentinel5dl

Sentinel-5(P) Downloader
https://sentinel5dl.emissions-api.org
MIT License
12 stars 8 forks source link

downloaded file rename error #70

Closed craigmillernz closed 2 years ago

craigmillernz commented 4 years ago

I encounter a file rename error when running this code Note this only occurs under Windows and not in Linux (ubuntu18.04).

from sentinel5dl import search, download
from sentinelsat import SentinelAPI, read_geojson, geojson_to_wkt
import certifi
import logging
import os
data_dir = 'D:/TropOMI/'
os.chdir(data_dir)

footprint = geojson_to_wkt(read_geojson('Tonga.geojson'))

sentinel5dl.ca_info = certifi.where()
sentinel5dl.logger.setLevel(logging.DEBUG)
# Search for Sentinel-5 products
result = search(
        polygon=footprint,
        begin_ts='2020-05-12T00:00:00.000Z',
        end_ts='2020-05-13T00:00:00.000Z',
        product='L2__SO2___',
        processing_level='L2',
        processing_mode='Near real time')

# Download found products to the local folder
download(result.get('products'), output_dir = data_dir)
Traceback (most recent call last):

  File "D:\Dropbox\python\tropomi_scripts\sentinel5dl_tests.py", line 30, in <module>
    download(result.get('products'), output_dir = data_dir)

  File "C:\Users\xxxx\Anaconda3\lib\site-packages\sentinel5dl\__init__.py", line 231, in download
    __http_request(f'{base_path}/$value', filename)

  File "C:\Users\xxxx\Anaconda3\lib\site-packages\sentinel5dl\__init__.py", line 113, in __http_request
    os.rename(f'{filename}.tmp', filename)

PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'D:/Dropbox/S5P_NRTI_L2__SO2____20200512T020639_20200512T021139_13360_01_010108_20200512T025748.nc.tmp' -> 'D:/Dropbox/S5P_NRTI_L2__SO2____20200512T020639_20200512T021139_13360_01_010108_20200512T025748.nc

I wonder if this is caused by curl.close() in __http_request not finishing properly before the os.rename()occurs?