Here is some code I got from one of the other responses:
UrlDownloadToFile, https://gist.github.com/gimoya/5821469/raw/034b2766bbcbe70e2a8e93b72d1ec8723351a8f8/Veg%C3%96K-Abk%C3%BCrzungen, hotstrings.ahk
if(ErrorLevel || !FileExist("hotstrings.ahk") ) {
msgbox, Download failed!
ExitApp
}
Run, hotstrings.ahk
I tried to modify it to my needs by changing the URL but it just shows this sign:
Download failed and that the compressed zip folder is invalid.
If you just get the direct download link for the Dropbox file, it works just fine:
URLDownloadToFile, % "https://www.dropbox.com/s/t1emirfeqbnu8tu/hello.txt?dl=1", % "my_cool_file.txt"
(Thanks to the first link on Google for this random example Dropbox file)
Adding ?dl=1 gives the direct link.
Related
I have a web.py server hosted on pythonanywhere.com doing some handy things with python.
Now I'd like to just serve a straightforward html file from the same server i.e. just return the contents of a static html file to the client
The comments/answers below state that it should be possible, out of the box, to serve static files in the static directory, located in the same directory as the main python file which contains the following :
import web
urls = (
'/', 'hello'
)
app = web.application(urls, globals())
class hello:
def GET(self):
return 'Hello, Joe'
if __name__ == "__main__":
app.run()
The server above works fine, when I go to http://myhost/ it displays "Hello , Joe".
The directory static exists and contains a file small.jpg but when I try the url http://myhost/static/small.jpg it gives me "not found"
Previous text of question up to Nov 9th 2022 is below :
original question title : Trying to return a html file in web.py but getting "No template named ....." error message
So I've looked at the web.py documentation on serving static files and templating and I think the following code should work :
import web
render = web.template.render('static/')
# have also tried render = web.template.render('/full/path/to/static/')
urls = (
'/getlatlongEIRCODE', 'getlatlongEIRCODE', #other stuff
'/getlatlongGOOGLE', 'getlatlongGOOGLE', #other stuff
'/getmonthlyPV', 'getmonthlyPV', #other stuff
'/Tomas', 'Tomas',
)
class Tomas:
def GET(self):
return render.Tomas()
I have created a folder static at the same level as my file above (which works fine for the other scripts) and i have created a file Tomas.html in the static folder containing
<h1>Help me</h1>
However I get an error message when I go to https://example.com/Tomas
<class 'AttributeError'> at /Tomas
No template named Tomas
P.S. From the static files page it seems to say I should just be able to put the Tomas.html file in a folder called "static" and then access is via https://example.com/static/Tomas.html but that is not working (it returns "not found")
You're using a relative path to your template directory without paying attention to the working directory. See https://help.pythonanywhere.com/pages/NoSuchFileOrDirectory/
You're working too hard. 'static' is built in.
As the documentation says, http://localhost/static/logo.png will return the file logo.png from the existing directory static, which is relative to your webserver root.
Do not use render() for this (not needed). Also, do not list your desired file ('/Tomas') in the urls list (not needed).
Anything under the static directory can be accessed with the url https://localhost/static/...
"static" is hardcoded in the web.py server, so you cannot (easily) change this to some other folder. The suggestion in the web.py documents is to have nginx or apache host your application and use an Alias there to go to web.py static. (I think you can also add StaticMiddleware to your web.py application, but you'd need to investigate that yourself -- look at web.application.run()
The case of the disappearing /static/ directory was related to the fact that I'm hosting on pythonanywhere.com
Even though the web.py documentation says that the /static/ folder is plugged in by default, that's not the case in pythonanywhere and you need to expressly make the link between the url http://yourhost/static/ and /path/to/static in the Web part of the dashboard.
I have generated a box file from a png image then I followed this tutorial:
https://pretius.com/how-to-prepare-training-files-for-tesseract-ocr-and-improve-characters-recognition/ to generate custom traineddata file.
I encountered an error when I tried to use the generated traineddata alongside with Pytesseract.
and i got this kind of error:
raise TesseractError(proc.returncode, get_errors(error_string))
pytesseract.pytesseract.TesseractError: (-4, "read_params_file:
Can't open txt read_params_file: Can't open txt read_params_file: Can't open txt read_params_file: Can't open txt Error: LSTM requested, but not present!! Loading tesseract. mgr->GetComponent(TESSDATA_NORMPROTO, &fp)
:Error:Assert failed:in file adaptmatch.cpp, line 552")
I'm using Tesseract version 5.0
This is my config options
traineddata = f'+eng+lav+lav2'
config = f'-l {traineddata} --oem 1 --psm 3 {tessdata_dir}'
I followed the same tutorial and encountered the exact same error. At my first tries the ***.traineddata didn't generated well, and I findout that one file was missing (normproto). So I just cleaned all the generated files (except the corrected .box files) and rerun the train process, and everything worked fine on the second attempt.
So I want the automated test case to find the file and upload it. This is what I found with my research but no luck with it.
WebUI.openBrowser('C:\\\\Users\\\\User\\\\Desktop\\\\Katalon Articles\\\\File Upload\\\\UploadFile.html')
'Maximize the window\r\n'
WebUI.maximizeWindow()
'Uploading the File using Send Keys method by passing the File path'
WebUI.sendKeys(findTestObject('Upload File'), 'C:\\\\Users\\\\Public\\\\Pictures\\\\Sample Pictures\\\\Desert.jpg')
'Capturing the file name after upload and storing it in a variable'
FilePath = WebUI.getAttribute(findTestObject('Upload File'), 'value')
'Verifying the Actual path and Expected path of file'
WebUI.verifyMatch(FilePath, 'C:\\fakepath\\Desert.jpg', false)
I have an E2E test to upload a file to the application which works on my local machine but fails to run on Browserstack. But fails with reason :
invalid argument: File not found : /home/travis/build/xx/xx/e2e/src/xx/testfile
Here is the code
let fileToUpload = 'testfile';
let absolutePath = path.resolve(__dirname, fileToUpload);
await browser.setFileDetector(new remote.FileDetector());
let fileElem = $('input[type="file"]');
await fileElem.sendKeys(absolutePath);
I have the files upload in my code base for travis to pick them.
Any inputs are appreciated.
Thanks
Since the file upload is working from your local machine, you can try using the Local File Detector Option.
driver.setFileDetector(new LocalFileDetector());
driver.get("http://www.fileconvoy.com/");
driver.findElement(By.id("upfile_0")).sendKeys("C:\\Users\\hello\\url.txt");
driver.findElement(By.id("readTermsOfUse")).click();
driver.findElement(By.name("form_upload")).submit();
The above code snippet will upload a file located on the local machine. The same details are available here: https://www.browserstack.com/automate/java#enhancements-uploads-downloads
You can port this in the language of your choice.
((RemoteWebDriver) driver).setFileDetector(new LocalFileDetector());
driver.get("https://www.monsterindia.com/seeker/registration");
WebElement browser = driver.findElement(By.xpath("//*[#id=\"file-upload\"]"));
//Upload button xpath
browser.sendKeys("add here upload file path");
System.out.println("File upload Successfully");
This will also simple way to upload file. I have worked this code in Chrome browser.
This code worked for me to run the test in BrowserStack. I'm using Java-selenium-Jenkins-BrowserStack
WebElement uploadFile = driver.findElement(By.xpath("//input[#type='file']"));
((RemoteWebElement)uploadFile).setFileDetector(new LocalFileDetector());
upload_file.sendKeys(System.getProperty("user.dir")+"/src/main/java/resources/common/<Name of your file>.csv");
I am importing products using the built in CSV import (System - import - products)
All my data is imported fine, but I get an error
Imported resource (image) could not be downloaded from external resource due to timeout or access permissions in rows: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
In my css I have written the base_image path as ://mywebsite.ca/pub/media/import/img/hose/jpg/Ach7938.jpg
as a test I removed my folder structure, edited the csv and tried this and got same problem, same error http://mywebsite.ca/pub/media/import/Ach7938.jpg
I tried writing file path as /pub/media/import/img/hose/jpg/Ach7938.jpg
but it won't let me past the "check data" validator.
I confirmed the permissions on the folders and files is 775
I am using PHP 5.6, I tried 7 but it broke the whole site in many different ways, so that isn't an option
As a side note, if I run this 20 times in a row, the entire site hangs and import won't work again until I do a full system restore (whats up with that?)
Can I put the images on a different server and link to them that way?
Image path can be relative path or simple name. I've imported with both and it worked. In my case issue was the images given in path wasn't available in folder. I tried it with importing available and not-available image and was getting error in case when that image wasn't available.
Path can be any one ,it isn't must to use pub/media/import only.
For the import images issue i have fixed the issue from Uploader.php file. change below file path code and success working import images.
File path:
magento/vendor/magento/module-catalog-import-export/Model/Import/Uploader.php
Find the below line from line number 201:
$filePath = $this->_directory->getRelativePath($filePath . $fileName);
Replace with:
$filePath = strpos($filePath, $fileName) !== false ?
$filePath:$this->_directory->getRelativePath($filePath . $fileName);
For More information refer to this GitHub link:
https://github.com/magento/magento2/pull/20761/commits/8612789375b0c173f0ba852c587882af6ff8bc7f
The Images File Directory needs to be set relative to the Magento doc root.
For example if your product images are in pub/media/catalog/product
Set that as your Images File Directory.