Python Logging Error












2















So I'm using the python logging module for the first time, and I'm receiving an error I cannot find any information on.



At the start of my file, I have the following:



logging.basicConfig(level=logging.INFO, filename='logs', filemode='a+', format='[%(asctime)-15s] %(levelname)-8s %(message)s')


The line that's throwing the error:



logging.info(f'Downloading: {file_name}t{local_file_path}t{os.path.abspath(local_file_path)}')

--- Logging error ---
Traceback (most recent call last):
File "C:Python36liblogging__init__.py", line 996, in emit
self.flush()
File "C:Python36liblogging__init__.py", line 976, in flush
self.stream.flush()
OSError: [Errno 22] Invalid argument
Call stack:
File "Main.py", line 81, in <module>
main()
File "C:Python36libsite-packagesclickcore.py", line 722, in __call__
return self.main(*args, **kwargs)
File "C:Python36libsite-packagesclickcore.py", line 697, in main
rv = self.invoke(ctx)
File "C:Python36libsite-packagesclickcore.py", line 895, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "C:Python36libsite-packagesclickcore.py", line 535, in invoke
return callback(*args, **kwargs)
File "Main.py", line 32, in main
work_tv(ftp, ext)
File "Main.py", line 76, in work_tv
logging.info(f'Downloading: {file_name}t{local_file_path}t{os.path.abspath(local_file_path)}')
Message: 'Downloading: Preacher S02E13t./Preacher/Season 2/Preacher S02E13.mkvtZ:\TV\Preacher\Season 2\Preacher S02E13.mkv'
Arguments: ()


I don't understand this error. The first 8 times it ran successfully without a problem. However the last two, it has thrown this identical error. Can someone please explain it to me.










share|improve this question























  • Don't use logging directly, you should use logger from logging: logger = logging.getLogger(name), and then use logger.info('blahblah').

    – Menglong Li
    Sep 12 '17 at 3:01













  • Your logging code looks good. It's not the source of the exception. Windows throw Errno 22 for many mysterious reasons. See stackoverflow.com/questions/23688492/… and social.msdn.microsoft.com/Forums/en-US/…. Could you expand on your example? A full script that reproduces the issue would be nice. I suspect this is a Windows issue, what version of Windows are you running?

    – Matt Hardcastle
    Sep 12 '17 at 14:59













  • @MattHardcastle I'm running Windows 10 64-bit Home and Python 3.6.2 64-bit. I implemented the changes that @MenglongLi suggested and have been without errors thus far, but it's still early. No downloads today. There's nothing I can really expand on. I don't use any other logging methods, just info.

    – Spedwards
    Sep 13 '17 at 2:26











  • I updated my answer.

    – Vinay Sajip
    Sep 14 '17 at 11:11
















2















So I'm using the python logging module for the first time, and I'm receiving an error I cannot find any information on.



At the start of my file, I have the following:



logging.basicConfig(level=logging.INFO, filename='logs', filemode='a+', format='[%(asctime)-15s] %(levelname)-8s %(message)s')


The line that's throwing the error:



logging.info(f'Downloading: {file_name}t{local_file_path}t{os.path.abspath(local_file_path)}')

--- Logging error ---
Traceback (most recent call last):
File "C:Python36liblogging__init__.py", line 996, in emit
self.flush()
File "C:Python36liblogging__init__.py", line 976, in flush
self.stream.flush()
OSError: [Errno 22] Invalid argument
Call stack:
File "Main.py", line 81, in <module>
main()
File "C:Python36libsite-packagesclickcore.py", line 722, in __call__
return self.main(*args, **kwargs)
File "C:Python36libsite-packagesclickcore.py", line 697, in main
rv = self.invoke(ctx)
File "C:Python36libsite-packagesclickcore.py", line 895, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "C:Python36libsite-packagesclickcore.py", line 535, in invoke
return callback(*args, **kwargs)
File "Main.py", line 32, in main
work_tv(ftp, ext)
File "Main.py", line 76, in work_tv
logging.info(f'Downloading: {file_name}t{local_file_path}t{os.path.abspath(local_file_path)}')
Message: 'Downloading: Preacher S02E13t./Preacher/Season 2/Preacher S02E13.mkvtZ:\TV\Preacher\Season 2\Preacher S02E13.mkv'
Arguments: ()


I don't understand this error. The first 8 times it ran successfully without a problem. However the last two, it has thrown this identical error. Can someone please explain it to me.










share|improve this question























  • Don't use logging directly, you should use logger from logging: logger = logging.getLogger(name), and then use logger.info('blahblah').

    – Menglong Li
    Sep 12 '17 at 3:01













  • Your logging code looks good. It's not the source of the exception. Windows throw Errno 22 for many mysterious reasons. See stackoverflow.com/questions/23688492/… and social.msdn.microsoft.com/Forums/en-US/…. Could you expand on your example? A full script that reproduces the issue would be nice. I suspect this is a Windows issue, what version of Windows are you running?

    – Matt Hardcastle
    Sep 12 '17 at 14:59













  • @MattHardcastle I'm running Windows 10 64-bit Home and Python 3.6.2 64-bit. I implemented the changes that @MenglongLi suggested and have been without errors thus far, but it's still early. No downloads today. There's nothing I can really expand on. I don't use any other logging methods, just info.

    – Spedwards
    Sep 13 '17 at 2:26











  • I updated my answer.

    – Vinay Sajip
    Sep 14 '17 at 11:11














2












2








2


1






So I'm using the python logging module for the first time, and I'm receiving an error I cannot find any information on.



At the start of my file, I have the following:



logging.basicConfig(level=logging.INFO, filename='logs', filemode='a+', format='[%(asctime)-15s] %(levelname)-8s %(message)s')


The line that's throwing the error:



logging.info(f'Downloading: {file_name}t{local_file_path}t{os.path.abspath(local_file_path)}')

--- Logging error ---
Traceback (most recent call last):
File "C:Python36liblogging__init__.py", line 996, in emit
self.flush()
File "C:Python36liblogging__init__.py", line 976, in flush
self.stream.flush()
OSError: [Errno 22] Invalid argument
Call stack:
File "Main.py", line 81, in <module>
main()
File "C:Python36libsite-packagesclickcore.py", line 722, in __call__
return self.main(*args, **kwargs)
File "C:Python36libsite-packagesclickcore.py", line 697, in main
rv = self.invoke(ctx)
File "C:Python36libsite-packagesclickcore.py", line 895, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "C:Python36libsite-packagesclickcore.py", line 535, in invoke
return callback(*args, **kwargs)
File "Main.py", line 32, in main
work_tv(ftp, ext)
File "Main.py", line 76, in work_tv
logging.info(f'Downloading: {file_name}t{local_file_path}t{os.path.abspath(local_file_path)}')
Message: 'Downloading: Preacher S02E13t./Preacher/Season 2/Preacher S02E13.mkvtZ:\TV\Preacher\Season 2\Preacher S02E13.mkv'
Arguments: ()


I don't understand this error. The first 8 times it ran successfully without a problem. However the last two, it has thrown this identical error. Can someone please explain it to me.










share|improve this question














So I'm using the python logging module for the first time, and I'm receiving an error I cannot find any information on.



At the start of my file, I have the following:



logging.basicConfig(level=logging.INFO, filename='logs', filemode='a+', format='[%(asctime)-15s] %(levelname)-8s %(message)s')


The line that's throwing the error:



logging.info(f'Downloading: {file_name}t{local_file_path}t{os.path.abspath(local_file_path)}')

--- Logging error ---
Traceback (most recent call last):
File "C:Python36liblogging__init__.py", line 996, in emit
self.flush()
File "C:Python36liblogging__init__.py", line 976, in flush
self.stream.flush()
OSError: [Errno 22] Invalid argument
Call stack:
File "Main.py", line 81, in <module>
main()
File "C:Python36libsite-packagesclickcore.py", line 722, in __call__
return self.main(*args, **kwargs)
File "C:Python36libsite-packagesclickcore.py", line 697, in main
rv = self.invoke(ctx)
File "C:Python36libsite-packagesclickcore.py", line 895, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "C:Python36libsite-packagesclickcore.py", line 535, in invoke
return callback(*args, **kwargs)
File "Main.py", line 32, in main
work_tv(ftp, ext)
File "Main.py", line 76, in work_tv
logging.info(f'Downloading: {file_name}t{local_file_path}t{os.path.abspath(local_file_path)}')
Message: 'Downloading: Preacher S02E13t./Preacher/Season 2/Preacher S02E13.mkvtZ:\TV\Preacher\Season 2\Preacher S02E13.mkv'
Arguments: ()


I don't understand this error. The first 8 times it ran successfully without a problem. However the last two, it has thrown this identical error. Can someone please explain it to me.







python logging






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Sep 12 '17 at 2:52









SpedwardsSpedwards

1,84492768




1,84492768













  • Don't use logging directly, you should use logger from logging: logger = logging.getLogger(name), and then use logger.info('blahblah').

    – Menglong Li
    Sep 12 '17 at 3:01













  • Your logging code looks good. It's not the source of the exception. Windows throw Errno 22 for many mysterious reasons. See stackoverflow.com/questions/23688492/… and social.msdn.microsoft.com/Forums/en-US/…. Could you expand on your example? A full script that reproduces the issue would be nice. I suspect this is a Windows issue, what version of Windows are you running?

    – Matt Hardcastle
    Sep 12 '17 at 14:59













  • @MattHardcastle I'm running Windows 10 64-bit Home and Python 3.6.2 64-bit. I implemented the changes that @MenglongLi suggested and have been without errors thus far, but it's still early. No downloads today. There's nothing I can really expand on. I don't use any other logging methods, just info.

    – Spedwards
    Sep 13 '17 at 2:26











  • I updated my answer.

    – Vinay Sajip
    Sep 14 '17 at 11:11



















  • Don't use logging directly, you should use logger from logging: logger = logging.getLogger(name), and then use logger.info('blahblah').

    – Menglong Li
    Sep 12 '17 at 3:01













  • Your logging code looks good. It's not the source of the exception. Windows throw Errno 22 for many mysterious reasons. See stackoverflow.com/questions/23688492/… and social.msdn.microsoft.com/Forums/en-US/…. Could you expand on your example? A full script that reproduces the issue would be nice. I suspect this is a Windows issue, what version of Windows are you running?

    – Matt Hardcastle
    Sep 12 '17 at 14:59













  • @MattHardcastle I'm running Windows 10 64-bit Home and Python 3.6.2 64-bit. I implemented the changes that @MenglongLi suggested and have been without errors thus far, but it's still early. No downloads today. There's nothing I can really expand on. I don't use any other logging methods, just info.

    – Spedwards
    Sep 13 '17 at 2:26











  • I updated my answer.

    – Vinay Sajip
    Sep 14 '17 at 11:11

















Don't use logging directly, you should use logger from logging: logger = logging.getLogger(name), and then use logger.info('blahblah').

– Menglong Li
Sep 12 '17 at 3:01







Don't use logging directly, you should use logger from logging: logger = logging.getLogger(name), and then use logger.info('blahblah').

– Menglong Li
Sep 12 '17 at 3:01















Your logging code looks good. It's not the source of the exception. Windows throw Errno 22 for many mysterious reasons. See stackoverflow.com/questions/23688492/… and social.msdn.microsoft.com/Forums/en-US/…. Could you expand on your example? A full script that reproduces the issue would be nice. I suspect this is a Windows issue, what version of Windows are you running?

– Matt Hardcastle
Sep 12 '17 at 14:59







Your logging code looks good. It's not the source of the exception. Windows throw Errno 22 for many mysterious reasons. See stackoverflow.com/questions/23688492/… and social.msdn.microsoft.com/Forums/en-US/…. Could you expand on your example? A full script that reproduces the issue would be nice. I suspect this is a Windows issue, what version of Windows are you running?

– Matt Hardcastle
Sep 12 '17 at 14:59















@MattHardcastle I'm running Windows 10 64-bit Home and Python 3.6.2 64-bit. I implemented the changes that @MenglongLi suggested and have been without errors thus far, but it's still early. No downloads today. There's nothing I can really expand on. I don't use any other logging methods, just info.

– Spedwards
Sep 13 '17 at 2:26





@MattHardcastle I'm running Windows 10 64-bit Home and Python 3.6.2 64-bit. I implemented the changes that @MenglongLi suggested and have been without errors thus far, but it's still early. No downloads today. There's nothing I can really expand on. I don't use any other logging methods, just info.

– Spedwards
Sep 13 '17 at 2:26













I updated my answer.

– Vinay Sajip
Sep 14 '17 at 11:11





I updated my answer.

– Vinay Sajip
Sep 14 '17 at 11:11












1 Answer
1






active

oldest

votes


















0














The fact that it failed on a self.stream.flush() implies that the file being written to (presumably logs) has already been closed or is not writable for some other reason.



Update: If you need to deal with this, subclass the handler and override the emit() method to do what you need to recover from the error.






share|improve this answer


























  • Since the script is running continuously 24/7, I suppose the file is being closed. How would I go about opening it back up whenever it closes for the logger?

    – Spedwards
    Sep 14 '17 at 1:59













Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f46167158%2fpython-logging-error%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














The fact that it failed on a self.stream.flush() implies that the file being written to (presumably logs) has already been closed or is not writable for some other reason.



Update: If you need to deal with this, subclass the handler and override the emit() method to do what you need to recover from the error.






share|improve this answer


























  • Since the script is running continuously 24/7, I suppose the file is being closed. How would I go about opening it back up whenever it closes for the logger?

    – Spedwards
    Sep 14 '17 at 1:59


















0














The fact that it failed on a self.stream.flush() implies that the file being written to (presumably logs) has already been closed or is not writable for some other reason.



Update: If you need to deal with this, subclass the handler and override the emit() method to do what you need to recover from the error.






share|improve this answer


























  • Since the script is running continuously 24/7, I suppose the file is being closed. How would I go about opening it back up whenever it closes for the logger?

    – Spedwards
    Sep 14 '17 at 1:59
















0












0








0







The fact that it failed on a self.stream.flush() implies that the file being written to (presumably logs) has already been closed or is not writable for some other reason.



Update: If you need to deal with this, subclass the handler and override the emit() method to do what you need to recover from the error.






share|improve this answer















The fact that it failed on a self.stream.flush() implies that the file being written to (presumably logs) has already been closed or is not writable for some other reason.



Update: If you need to deal with this, subclass the handler and override the emit() method to do what you need to recover from the error.







share|improve this answer














share|improve this answer



share|improve this answer








edited Sep 14 '17 at 11:11

























answered Sep 13 '17 at 7:55









Vinay SajipVinay Sajip

70.6k8128143




70.6k8128143













  • Since the script is running continuously 24/7, I suppose the file is being closed. How would I go about opening it back up whenever it closes for the logger?

    – Spedwards
    Sep 14 '17 at 1:59





















  • Since the script is running continuously 24/7, I suppose the file is being closed. How would I go about opening it back up whenever it closes for the logger?

    – Spedwards
    Sep 14 '17 at 1:59



















Since the script is running continuously 24/7, I suppose the file is being closed. How would I go about opening it back up whenever it closes for the logger?

– Spedwards
Sep 14 '17 at 1:59







Since the script is running continuously 24/7, I suppose the file is being closed. How would I go about opening it back up whenever it closes for the logger?

– Spedwards
Sep 14 '17 at 1:59






















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f46167158%2fpython-logging-error%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

How to send String Array data to Server using php in android

Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents

Is anime1.com a legal site for watching anime?