Saving Excel file in C:\ using interop.excel throws error - excel-interop

I have a wpf application and I am saving an Excel file using following code. If I select the file path as "C:\" it throws an error. No other file path has this issue.
Please help.
excelWorkbook.SaveAs(saveAsPath, XlFileFormat.xlWorkbookNormal, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, XlSaveAsAccessMode.xlExclusive,
Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
EDIT
File name: C:\2347_H4141001_axm2312_20110627_042821.xls
The error is:
The file could not be accessed. Try one of the following:
• Make sure the specified folder exists.
• Make sure the folder that contains the file is not read-only.
• Make sure the file name does not contain any of the following characters: < > ? [ ] : | or *
• Make sure the file/path name doesn't contain more than 218 characters.

Do you have checked permissions? Windows blocks writes to ROOT of drives like C: by default.
The characters ":" and "\" may be the cause, try to use # before, like this: #"C:\nameOfFile

Related

No module named 'twilio'

I am trying to use twilio to send a text message...when I put the demo script in a texteditor, ave it as something.py and run it from terminal, I receive the text message.
However, when I copy and paste the same code into Spyder (Anaconda 3 environment, Python 3.8) I get the following error.
Here is the code:
from twilio.rest import Client
account_sid = 'xxx'
auth_token = 'xxx'
client = Client(account_sid, auth_token)
message = client.messages \
.create(
body="Test.",
from_='x',
to='xxx'
)
print(message.sid)
And here is there error:
File "xxx", line 14, in <module>
import twilio
ModuleNotFoundError: No module named 'twilio'
I have installed with pip, pip3, Conda, all that.
I'm not really used to this anaconda environment thing, but when I search for the package "twilio" the only thing that shows up is r-Twilio. I imagine this is something to do with the problem, but I've no idea. I tried creating a new environment with python 2.7 and again only saw the r-twilio thing.

How to load LUA modules in aquarium/scrapy-splash?

I am working on a LUA script for scrapy-splash and want to use the socket.http module.
The module is installed, I have disabled the sandbox and configured the package path. But I can't get it to work.
My environment is aquarium on Linux.
I have installed luasocket using luarocks and added
--disable-lua-sandbox --lua-package-path "/usr/local/share/lua/5.1/?.lua;/usr/local/share/lua/5.1/?/?.lua"
to the splash instance in docker-compose.yml.
When I run the script I get the following error:
"error": {"info": {"type": "LUA_INIT_ERROR", "message": "[string \"<python>\"]:1: module 'socket.http' not found:
no field package.preload['socket.http']
no file '/app/splash/lua_modules/socket/http.lua'
no file '/app/splash/lua_modules/libs/socket/http.lua'
no file '/usr/local/share/lua/5.1/socket/http.lua'
no file '/usr/local/share/lua/5.1/socket/http/socket/http.lua'
no file '/usr/local/share/lua/5.2/socket/http.lua'
no file '/usr/local/share/lua/5.2/socket/http/init.lua'
no file '/usr/local/lib/lua/5.2/socket/http.lua'
no file '/usr/local/lib/lua/5.2/socket/http/init.lua'
no file '/usr/share/lua/5.2/socket/http.lua'
no file '/usr/share/lua/5.2/socket/http/init.lua'
no file './socket/http.lua'
no file '/usr/local/lib/lua/5.2/socket/http.so'
no file '/usr/lib/x86_64-linux-gnu/lua/5.2/socket/http.so'
no file '/usr/lib/lua/5.2/socket/http.so'
no file '/usr/local/lib/lua/5.2/loadall.so'
no file './socket/http.so'
no file '/usr/local/lib/lua/5.2/socket.so'
no file '/usr/lib/x86_64-linux-gnu/lua/5.2/socket.so'
no file '/usr/lib/lua/5.2/socket.so'
no file '/usr/local/lib/lua/5.2/loadall.so'
no file './socket.so'"}, "description": "Error happened while executing Lua script", "type": "ScriptError", "error": 400}, "qsize": 0, "status_code": 400}
Even though the file /usr/local/share/lua/5.1/socket/http.lua exists on my machine. I have also tried to chmod 777 the file but it still throws the error.
It turned out that there was no need for me to use socket.http.
I am using splash:http_get and splash:http_post now and it is working fine.

Docker: Can't read class path resource from spring boot application

Reading a classpath resource as,
try {
final ClassPathResource classPathResource = new ClassPathResource(format("location%sGeoLite2-City.mmdb", File.separator));
final File database = classPathResource.getFile();
dbReader = new DatabaseReader.Builder(database).build();
} catch (Exception e) {
System.out.println("Exception: " + e);
}
I've packaged this with docker using following Dockerfile,
FROM java:8
ADD build/libs/*.jar App.jar
CMD java -jar App.jar
But while running this application as docker run -p 8080:8080 app-image I can hit the application endpoint and from application logs I can see it fails to read this file (following is from logs),
Exception: java.io.FileNotFoundException: class path resource [location/GeoLite2-City.mmdb] cannot be resolved to absolute file path because it does not reside in the file system: jar:file:/App.jar!/BOOT-INF/classes!/location/GeoLite2-City.mmdb
Would appreciate any comment, Things to know before you comment,
**- Running on windows 10, intellij 2018.2, jdk 8
- Can run application successfully with intellij as well as command line
- File exists in jar (I did extract jar and checked )
**
Since you are using springboot you can try to use the following annotation for loading your classpath resource. Worked for me because I had the same exception. Be aware that the directory "location" must be under the src/main/resources folder:
#Value("classpath:/location/GeoLite2-City.mmdb")
private Resource geoLiteCity;
Without springboot you could try:
try (InputStream inputStream = getClass().getClassLoader().getResourceAsStream("/location/GeoLite2-City.mmdb")) {
... //convert to file and other stuff
}
Also the answers before were correct as the use of "/" is not good at all and File.separator would be the best choice.
It is not a good approach to use slashes.
Always use File Seperators as they work irrespective of System OS.
Change
(location\\GeoLite2-City.mmdb)
to
("location"+ File.separator +"GeoLite2-City.mmdb")
Refer this for more.
https://www.journaldev.com/851/java-file-separator-separatorchar-pathseparator-pathseparatorchar
Difference between File.separator and slash in paths
Had the same issue, the file worked when running the Spring boot app but was not working in Docker. My issue got resolved by using ClassPathResource for the resource and reading the resource as stream using InputStreamReader.
Resource resource = new ClassPathResource("test-xyz.json");
InputStream inputStream = null;
try {
inputStream = resource.getInputStream();
Reader reader = new InputStreamReader(inputStream, "UTF-8");
....

GridFS + CarrierWave + nginx unable to get file

In my project I upload audiofiles to GridFS using CarrierWave gem. After uploading file is saved to GridFS properly but in my application I am unable to get it from GridFS with MongoFiles Tool or with GridFS-nginx module.
mongofiles get audiotracks/4dfb70d6bcd73f3488000002/data
command leads to this error:
assertion: 13325 couldn't open file: audiotracks/4dfb70d6bcd73f3488000002/data
The only way to get file is to use rails console and it works fine:
cc = Mongo::GridFileSystem.new(Mongo::Connection.new.db("test")).open('audiotracks/4dfb70d6bcd73f3488000002/data', 'r')
cc.read
So if you have encountered problem like this or have some ideas - plz let me know.
mongofiles get will try to write the file to disk with the same name and path as in GridFS.
Assertion 13325 happens when GridFS can't write the file like this.
You should check if the file path exists and you have the permission to write the file. Alternatively you could just provide a file name with the --local parameter.
mongofiles --local mytrack.mp3 get audiotracks/4dfb70d6bcd73f3488000002/data

Grails 1.3.5: How to configure Datasource.groovy to either connect to MySQL or SQL Server

The grails application I am developing could run against MySQL or SQL Server. I want to add a new property in application.properties file say
database.type=MySQL // or it could be SQLSERVER
How do I get this property in Datasource.groovy so that if it is MySQL I connect to MySQL server or it is SQLSERVER I connect to SQL Server?
Is this the correct way to do it? How can I do it?
EDIT: After reading and searching for options I figured the following way explained.
I have created config.properties file in /grails-app/conf/ folder.
driverClassName = com.microsoft.sqlserver.jdbc.SQLServerDriver
dataSource.url = jdbc:sqlserver://localhost:1433;databaseName=testDB
dataSource.username = sa
dataSource.password = sa
Also updated Config.groovy
grails.config.locations = ["classpath:config.properties"]
But I get the below error
Unable to load specified config location classpath:config.properties : class path resource [config.properties] cannot be opened because it does not exist
But if use
grails.config.locations = ["file:E:/workspace/SpringSource2.3.3/GRAILS_PRO/config.properties"]
The application starts up and is able to connect to the database. I don't want to use static file path. What is wrong when using classpath?
Have the same issue for both 'run-app' and 'war' mode i.e. same file does not exist error.
2nd EDIT:
After so much frustration of using classpath and not able to get it to work, I resorted to using environment property. Since server will have CATALINA_HOME defined, I used the below to build the path for external configuration file.
def CATALINA_HOME = "CATALINA_HOME"
def CONFIG_FILE_NAME = "db_config.properties"
if(!grails.config.locations || !(grails.config.locations instanceof List)) {
grails.config.locations = []
}
if(System.getenv(CATALINA_HOME)) {
def fullPath = System.getenv(CATALINA_HOME) + File.separator + "webapps" + File.separator + "${appName}" + File.separator + "WEB-INF" + File.separator + "classes" + File.separator + CONFIG_FILE_NAME
grails.config.locations << "file:" + fullPath
} else {
println "Missing configuration!"
}
The above solution is Tomcat specific. I really would like to see classpath version working!
Thank You.
Regards,
Jay Chandran.
put it in the home directory of the user which is running the instance of tomcat or there should be a .grails directory created for your app , put it under there

Resources