I have a webdev mounted folder which has pdf files.
I access these files through URL.
One of the files has name "test - (Copy).pdf".
When I generate the URL and try to open it, I get the error "HTTP error 404 not found".
I tried encoding the url using urllib with percent-encoding but still getting the same error.
2 encoded names that I tried:
test%20-%20(Copy).pdf
test%20-%20%28Copy%29.pdf
What am I doing wrong?
How can I solve this issue?
What is the best method to encode for any special characters?
I'll really appreciate any advice in this matter.
A sample code would be the best.
Below is the code that I am using which gives me "test+-+%28Copy%29.pdf" at the end.
The generate URL does not work.
I still get the same 404 error.
Is there any limitation on the special characters that I should consider?
Appreciate your help in this.
from java.net import URLEncoder
from java.nio.charset import StandardCharsets
def encode_url():
try:
url = "https://ServerAddress:443/system/webdev/ProjectName/FileSystem/NetworkDrives/MyFolder/test - (Copy).pdf"
# Encode only the path component that needs encoding
base_url = "https://ServerAddress:443/system/webdev/ProjectName/FileSystem/NetworkDrives/MyFolder/"
file_name = "test - (Copy).pdf"
# Use URLEncoder to encode the file name
encoded_file_name = URLEncoder.encode(file_name, StandardCharsets.UTF_8.toString())
# Form the complete encoded URL
encoded_url = base_url + encoded_file_name
print("Encoded URL:", encoded_url)
return encoded_url
except Exception as e:
# Print any exceptions that occur
print("An error occurred:", e)
# Call the function to encode the URL
encoded_url = encode_url()
print encoded_url
This looks like a bug in the WebDev module to me. You shouldn't even have to manually URL-encode anything, your browser will do that before it sends the request anyway.
I don't encode usually but since it was not working, I started exploring options. URL encoding is something that came to my mind first.
Even that is not helping.
I got to know from one of my colleagues that special characters in names poses this problem in Ignition when it comes to generating URLs.
I want to explore my options before I go to removing the special characters (like "()") from the filename, host the file to some other location with new name and get the URL from there.
If there is a way, please let me know.
I appreciate your response in this regard.
@pturmel I don't get any error neither in browser console nor in Gateway log.