質問編集履歴
1
コードブロックの使用なし➡あり リンク部分のリンクなし➡あり
title
CHANGED
File without changes
|
body
CHANGED
@@ -2,29 +2,54 @@
|
|
2
2
|
|
3
3
|
■以下、試したこと
|
4
4
|
・最初に出たエラー
|
5
|
-
|
6
|
-
|
5
|
+
```ここに言語を入力
|
6
|
+
File "<ipython-input-4-0a904a6ac562>", line 6
|
7
|
+
filename = "C:\Users\furug\Desktop\work\test2.csv"
|
8
|
+
^
|
9
|
+
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape
|
10
|
+
```
|
11
|
+
・解決のために参考にしたページ➡[リンク内容]((https://ja.stackoverflow.com/questions/11582/open%E9%96%A2%E6%95%B0%E3%82%92%E4%BD%BF%E3%81%86%E3%81%A8%E3%82%A8%E3%83%A9%E3%83%BC-unicode-error-%E3%81%8C%E5%87%BA%E3%81%A6%E3%81%97%E3%81%BE%E3%81%84%E3%81%BE%E3%81%99))
|
7
12
|
・対策した内容
|
8
13
|
raw文字を使えばエスケープは解釈され無いので r を付けて、r"C:\Users …… と書く事を試しました
|
9
14
|
・結果
|
10
15
|
別のエラー⓶が発生
|
11
16
|
|
12
17
|
・別のエラー⓶
|
18
|
+
```ここに言語を入力
|
19
|
+
UnicodeDecodeError Traceback (most recent call last)
|
20
|
+
<ipython-input-5-fe9ff54b74e4> in <module>
|
21
|
+
9 with open(filename, 'r') as f:
|
22
|
+
10 reader = csv.reader(f)
|
23
|
+
---> 11 header = next(reader)
|
24
|
+
12
|
25
|
+
13 for row in reader:
|
26
|
+
|
13
|
-
|
27
|
+
UnicodeDecodeError: 'cp932' codec can't decode byte 0xef in position 0: illegal multibyte sequence
|
14
|
-
|
28
|
+
```
|
15
|
-
|
29
|
+
・解決の為に参考にしたページ➡[リンク内容](https://qiita.com/Yuu94/items/9ffdfcb2c26d6b33792e)
|
16
30
|
・対策した内容
|
17
31
|
filename = r"C:\Users\furug\Desktop\work\test2.csv,encoding=utf-8_sig"と書いた
|
18
32
|
・結果
|
19
33
|
別のエラー⓷が発生
|
20
34
|
|
21
35
|
・別のエラー⓷
|
36
|
+
```ここに言語を入力
|
37
|
+
FileNotFoundError Traceback (most recent call last)
|
38
|
+
<ipython-input-6-10c16fac8532> in <module>
|
39
|
+
7
|
40
|
+
8 # CSVから読み込み
|
41
|
+
----> 9 with open(filename, 'r') as f:
|
42
|
+
10 reader = csv.reader(f)
|
43
|
+
11 header = next(reader)
|
44
|
+
|
22
|
-
|
45
|
+
FileNotFoundError: [Errno 2] No such file or directory: 'C:\Users\furug\Desktop\work\test2.csv,encoding=utf-8_sig'
|
46
|
+
```
|
23
47
|
ここで『そんなファイルないって言われても・・・』となり止まってしまいました。
|
24
48
|
|
25
49
|
|
26
50
|
### 現在のコードは以下です
|
27
51
|
|
52
|
+
```ここに言語を入力
|
28
53
|
import smtplib
|
29
54
|
from email.mime.text import MIMEText
|
30
55
|
|
@@ -99,4 +124,5 @@
|
|
99
124
|
subject = "Pythonによるテストメール"
|
100
125
|
body = create_mail_body(full_name)
|
101
126
|
mailer = Mailer(addr_to, subject, body)
|
102
|
-
mailer.send()
|
127
|
+
mailer.send()
|
128
|
+
```
|