FileNotFoundError when using the SDK with image urls that doesn't contain the scheme.
Closed this issue · 1 comments
adilentiq commented
Description
I get the following error when trying to call the Python SDK methods with URLs that doesn't contain the scheme(https:// or http://)
FileNotFoundError: The file at raw.githubusercontent.com/adilentiq/test-images/main/image-jpg.jpg does not exist.
Context
Runware Python SDK version: runware==0.2.7
Requirements
- Python installed on your workstation
Reproduction steps
-
Create a directory
-
Create a file e.g
prompt_enhance.py
with the following content:
from runware import Runware, IImageBackgroundRemoval
import asyncio
import os
from dotenv import load_dotenv
load_dotenv()
async def main() -> None:
runware = Runware(
api_key=os.getenv("RUNWARE_API_KEY"), url=os.getenv("RUNWARE_WSS_URL")
)
await runware.connect()
image_url = 'raw.githubusercontent.com/adilentiq/test-images/main/image-jpg.jpg'
payload = IImageBackgroundRemoval(inputImage=image_url)
print(f"Payload: {payload}")
result_image = await runware.imageBackgroundRemoval(payload)
print(f"Response : {result_image}")
asyncio.run(main())
- Create a virtual environment
python -m venv venv
- Activate venv environment
# Windows
venv\Scripts\activate
# Linux/MacOS
source venv/bin/activate
- Create a requirements.txt file with the following content:
aiofiles==23.2.1
asyncio==3.4.3
python-dotenv==1.0.1
runware==0.2.7
websockets==12.0
- Install project dependencies:
pip install -r requirements.txt
- Create
.env
file and set up environment variables
touch .env
source .env
Example
RUNWARE_API_KEY="your_runware_api_key"
RUNWARE_URL="wss://ws-api.runware.ai/v1"
RUNWARE_MODEL="runware:100@1"
- Run the python script
python prompt_enhance.py
Actual result
$ python image_background_removal.py
Payload: IImageBackgroundRemoval(inputImage='raw.githubusercontent.com/adilentiq/test-images/main/image-jpg.jpg', includeCost=False, outputType=None, outputFormat=None, rgba=[], postProcessMask=False, returnOnlyMask=False, alphaMatting=False, alphaMattingForegroundThreshold=None, alphaMattingBackgroundThreshold=None, alphaMattingErodeSize=None)
Traceback (most recent call last):
File "C:\Users\andre\playground\venv\Lib\site-packages\runware\utils.py", line 277, in fileToBase64
async with aiofiles.open(file_path, "rb") as file:
File "C:\Users\andre\playground\venv\Lib\site-packages\aiofiles\base.py", line 98, in __aenter__
self._obj = await self._coro
^^^^^^^^^^^^^^^^
File "C:\Users\andre\playground\venv\Lib\site-packages\aiofiles\threadpool\__init__.py", line 94, in _open
f = yield from loop.run_in_executor(executor, cb)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\andre\AppData\Local\Programs\Python\Python312\Lib\concurrent\futures\thread.py", line 58, in run
result = self.fn(*self.args, **self.kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: 'raw.githubusercontent.com/adilentiq/test-images/main/image-jpg.jpg'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\andre\playground\image_background_removal.py", line 26, in <module>
asyncio.run(main())
File "C:\Users\andre\AppData\Local\Programs\Python\Python312\Lib\asyncio\runners.py", line 194, in run
return runner.run(main)
^^^^^^^^^^^^^^^^
File "C:\Users\andre\AppData\Local\Programs\Python\Python312\Lib\asyncio\runners.py", line 118, in run
return self._loop.run_until_complete(task)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\andre\AppData\Local\Programs\Python\Python312\Lib\asyncio\base_events.py", line 687, in run_until_complete
return future.result()
^^^^^^^^^^^^^^^
File "C:\Users\andre\playground\image_background_removal.py", line 21, in main
result_image = await runware.imageBackgroundRemoval(payload)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\andre\playground\venv\Lib\site-packages\runware\base.py", line 418, in imageBackgroundRemoval
raise e
File "C:\Users\andre\playground\venv\Lib\site-packages\runware\base.py", line 414, in imageBackgroundRemoval
return await asyncRetry(
^^^^^^^^^^^^^^^^^
File "C:\Users\andre\playground\venv\Lib\site-packages\runware\async_retry.py", line 50, in asyncRetry
raise error
File "C:\Users\andre\playground\venv\Lib\site-packages\runware\async_retry.py", line 43, in asyncRetry
return await apiCall()
^^^^^^^^^^^^^^^
File "C:\Users\andre\playground\venv\Lib\site-packages\runware\base.py", line 425, in _removeImageBackground
image_uploaded = await self.uploadImage(inputImage)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\andre\playground\venv\Lib\site-packages\runware\base.py", line 663, in uploadImage
raise e
File "C:\Users\andre\playground\venv\Lib\site-packages\runware\base.py", line 661, in uploadImage
return await asyncRetry(lambda: self._uploadImage(file))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\andre\playground\venv\Lib\site-packages\runware\async_retry.py", line 50, in asyncRetry
raise error
File "C:\Users\andre\playground\venv\Lib\site-packages\runware\async_retry.py", line 43, in asyncRetry
return await apiCall()
^^^^^^^^^^^^^^^
File "C:\Users\andre\playground\venv\Lib\site-packages\runware\base.py", line 688, in _uploadImage
image_base64 = await fileToBase64(file) if isinstance(file, str) else file
^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\andre\playground\venv\Lib\site-packages\runware\utils.py", line 283, in fileToBase64
raise FileNotFoundError(f"The file at {file_path} does not exist.")
FileNotFoundError: The file at raw.githubusercontent.com/adilentiq/test-images/main/image-jpg.jpg does not exist.
Expected result
gorantosicpf commented
@adilentiq should be ok now