I got this error message in Scrapy spider, when I was writing the html of website to file.
with open('{}.html'.format(name), 'wb') as html_file:
FileNotFoundError: [Errno 2] No such file or directory:'CHARCOAL.html'
98% of the websites html were written correctly, however some threw this error (different file names).To make sure I printed the names and they all exist.
this is the code I use to write to files
#code here
name = response.xpath('//*[#id="itemTitle"]//text()').extract()[1]
with open('{}.html'.format(name), 'wb') as html_file:
html_file.write(response.body)
Related
I successfully transferred a text file (zero_conf.txt) to a Cisco IOSXE (Amsterdam) switch flash file system using python on the guestshell.
However when I try to open the text file using the following code:
with open('/flash/zero_conf.txt','r+') as f:
lines = f.readlines()
I am getting the following error:
with open('/flash/zero_conf.txt','r+') as f:
FileNotFoundError: [Errno 2] No such file or directory: '/flash/zero_conf.txt'
Please let me know if I am making a syntax error or what will be the correct way to open a text file on the Cisco iosxe python guestshell.
I am reading file from SharePoint and writitng in GCS bucket but when I run the function it gives me error "Error [Errno 30] Read-only file system: 'test.xlsx'"
here is the code
response = File.open_binary(ctx,location/file )
blob = bucket.blob('/sharepoint/' + doc)
print('connection')
with open("test.xlsx", "wb") as local_file:
blob.upload_from_file(local_file)
local_file.close()
please help if anyone know the solution of this error
Doing this open("test.xlsx", "wb") destroys the file. The file is also locked while open which causes the error message.
Change your code to open the file in read mode:
with open("test.xlsx", "rb") as local_file:
blob.upload_from_file(local_file)
local_file.close()
I am trying to open an online txt file using codecs.open. The code I have now is:
url = r'https://www.sec.gov/Archives/edgar/data/20/0000893220-96-000500.txt'
soup = BeautifulSoup(codecs.open(url, 'r',encoding='utf-8'), "lxml")
However, Python keeps reminding OSError:
OSError: [Errno 22] Invalid argument: 'https://www.sec.gov/Archives/edgar/data/20/0000893220-96-000500.txt'
I tried to replace "/" with "\". It still does not work. Is there any way to solve it? Since I have more than thousands of links to open, I do not quite want to download the online text files into my local drive.
I will appreciate it very much if someone can help here.
Thanks!
Is it something like this you're thinking of?
`from urllib.request import urlopen
url = urlopen('https://www.sec.gov/Archives/edgar/data/20/0000893220-96- 000500.txt')
html = url.read().decode('utf-8')
file = open('yourfile.txt', 'r')
file.read(html)
file.close`
This is the error I get when I try reading in the file.
logfile = open(r'C:/Users/AmitSingh/Desktop/Data/data_scientist_test/access_log/access.txt')
IOError: [Errno 2] No such file or directory: 'C:/Users/AmitSingh/Desktop/Data/data_scientist_test/access_log/access.txt'
logfile = open(r'C:/Users/AmitSingh/Desktop/Data/data_scientist_test/access_log/access.log')
with open(logfile, 'r') as read:
TypeError: coercing to Unicode: need string or buffer, file found
As you can see, when I try to read as a txt file it doesn't recognize the file. When I try to read as a log file it finds the file but generates an error.
Any suggestions on how to read this file in. It's a simple text file with rows like this
[02/Jan/2015:08:07:32] "GET /click?article_id=162&user_id=5475 HTTP/1.1" 200 4352
I've already tried changing the name of file to txt and that doesn't work.
Error one: the File
r'C:/Users/AmitSingh/Desktop/Data/data_scientist_test/access_log/access.txt'
does not exist.
Error two:
The file
'C:/Users/AmitSingh/Desktop/Data/data_scientist_test/access_log/access.log'
does exist but the function open(...) expects a string that is the full path to the file. In the line with open(logfile, 'r') as read: the variable logfile is already a file-object, not a string anymore.
Try the following:
logFilePath = r'C:/Users/AmitSingh/Desktop/Data/data_scientist_test/access_log/access.log'
with open(logFilePath, 'r') as fileObject:
pass # do the stuff you want with the file
# When you leave this indentation, the file object will be closed again
I am trying to read the log files or any other file and display in web browser using django and python
I used this code
data_file = open('/var/log/samba', 'r') # note -- 'r' not r
data = data_file.readlines() # returns a list of lines
I get this error
[Errno 21] Is a directory: '/var/log/samba'
You're trying to open a directory. Don't do that. Open a file instead.