Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 problems with python script and special characters
im new to python and am trying to use the below script but when i run it i get this error:
IOError: [Errno 2] No such file or directory: '/root/user/split_=?Utf-8?Q?Temp_Glass/Mas_1213_Tempest?=\r\n =?Utf-8?Q?Tian/Kontakt_byr=C3=A5.mbox'
The python script is attached below. it analyzes an .MBOX file and split it into smaller .MBOX files based on the label name.
I've copied the script from here:

I think the issue is that its trying to create a folder structure but that fails. I actually dont care about the folder structure , i just need the splitted mbox files. Anyone have any ideas on how to rewrite this?

script is here in full

#!/usr/bin/env python

# Adapted from:

import sys
import getopt
import mailbox

def main(argv):
	in_mbox = "inbox.mbox"
	prefix = "split_"
		opts, args = getopt.getopt(argv, "i:p:", ["infile=", "prefix="])
	except getopt.GetoptError:
		print("python -i  -p ")

	for opt, arg in opts:
		if opt in ("-i", "--infile"):
			in_mbox = arg
		elif opt in ("-p", "--prefix"):
			prefix = arg
	print("Processing file - " + in_mbox + " with prefix = " + prefix)
	boxes = {"inbox": mailbox.mbox(prefix+"Inbox.mbox", None, True), "sent": mailbox.mbox(prefix+"Sent.mbox", None, True),"archive":mailbox.mbox(prefix+"Archive.mbox", None, True)}

	for message in mailbox.mbox(in_mbox):
		gmail_labels = message["X-Gmail-Labels"]       # Could possibly be None.
		if not gmail_labels:
		gmail_labels = gmail_labels.lower()
		if "spam" in gmail_labels:
		elif "inbox" in gmail_labels:
		elif "sent" in gmail_labels:
			saved = False
			for label in gmail_labels.split(','):
				if label != "important" and label != "unread" and label != "starred" and label != "newsletters":
					box_name = prefix+label.title()+".mbox"
					if box_name not in boxes:
						boxes[box_name] = mailbox.mbox(box_name, None, True)
					saved = True
			if not saved:

if __name__ == "__main__":
Yoriz wrote Mar-29-2019, 12:27 AM:
Please post all code, output and errors (in it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Hi last08, welcome to the forums! Could you please post the entire error message? It shows more valueable information.

I assume as you have not written this script yourself, but found it somewhere online, now you don't want to learn anything about it, but just have somebody repair it for you? Correct me, if I'm wrong.

The way to go about it would be, contact the author. If you are familiar with Github, you can file an issue there, and state the error message.

If you would indeed like to understand the script and repair it yourself, we are ready to help you up to speed. Please do ask questions where you lack understanding.

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Automating to run python script 100 times by changing parameters pmt 0 108 Aug-10-2019, 02:58 PM
Last Post: pmt
  Group files according to first few characters in filename python_newbie09 7 162 Aug-02-2019, 06:34 AM
Last Post: cvsae
  Help with PyInstaller + Script "Failed to Execute Script" ironfelix717 2 170 Jul-31-2019, 02:18 PM
Last Post: ironfelix717
  Hollow triangle-drawing characters param error. phob0s 4 118 Jul-31-2019, 08:18 AM
Last Post: phob0s
  I need help with a python script nicopython 4 194 Jul-29-2019, 12:16 AM
Last Post: jonnin
  Python Script to repeat Photoshop action in folders and subfolders silfer 2 112 Jul-25-2019, 03:12 PM
Last Post: silfer
  Best method: Python script called from another app, package as complete executable ironfelix717 2 117 Jul-24-2019, 07:39 AM
Last Post: DeaD_EyE
  Having problems using 'or' in a 'if' statement? umut3806 2 230 Jul-21-2019, 11:33 PM
Last Post: umut3806
  Long command with characters not working in Python on Oracle Linux 7 iaas_infra 10 354 Jul-19-2019, 04:53 PM
Last Post: ichabod801
  Is this possible in Python? Auto-Send-to-printer on script run? pcsailor 8 1,003 Jul-19-2019, 09:33 AM
Last Post: perfringo

Forum Jump:

Users browsing this thread: 1 Guest(s)