Repository: spyder-ide/spyder

Issue:
UnicodeEncodeError when saving Help's history
 
<!---   *** BEFORE SUBMITTING: PASTE CLIPBOARD HERE TO COMPLETE YOUR REPORT ***   ---!>
<!--- **PLEASE READ:** Before submitting here, please carefully consult our *Troubleshooting Guide*: https://github.com/spyder-ide/spyder/wiki/Troubleshooting-Guide-and-FAQ and search the issues page for your error/problem, as most posted bugs are duplicates or easy fixes.

If you don't find anything, please provide a detailed step-by-step description (in English) of the problem and what led up to it below. Issue reports without a clear way to reproduce them will be closed. Thanks! --->

## Problem Description

### What steps will reproduce the problem?

<!--- You can use Markdown here --->


When I try to type the "(", the problem occurs.  

### Traceback
```python-traceback
  File "C:\Anaconda3\lib\site-packages\spyder\widgets\ipythonconsole\control.py", line 61, in keyPressEvent
    self._key_paren_left(text)
  File "C:\Anaconda3\lib\site-packages\spyder\widgets\ipythonconsole\control.py", line 53, in _key_paren_left
    self.show_object_info(last_obj)
  File "C:\Anaconda3\lib\site-packages\spyder\widgets\mixins.py", line 682, in show_object_info
    self.help.set_object_text(text, ignore_unknown=False)
  File "C:\Anaconda3\lib\site-packages\spyder\plugins\help.py", line 781, in set_object_text
    self.save_history()
  File "C:\Anaconda3\lib\site-packages\spyder\plugins\help.py", line 839, in save_history
    for index in range(self.combo.count())] ))
UnicodeEncodeError: 'gbk' codec can't encode character '\u2029' in position 62: illegal multibyte sequence
```

## Package Versions

* Spyder version: 3.2.8 
* Python version: 3.6.3
* Qt version: 5.6.2
* PyQt5 version: 5.6
* Operating system: Windows 10

### Dependencies

```
pyflakes >=0.6.0 :  1.6.0 (OK)
pycodestyle >=2.3:  2.3.1 (OK)
pygments >=2.0   :  2.2.0 (OK)
pandas >=0.13.1  :  0.20.3 (OK)
numpy >=1.7      :  1.13.3 (OK)
sphinx >=0.6.6   :  1.6.3 (OK)
rope >=0.9.4     :  0.10.5 (OK)
jedi >=0.9.0     :  0.10.2 (OK)
nbconvert >=4.0  :  5.3.1 (OK)
sympy >=0.7.3    :  1.1.1 (OK)
cython >=0.21    :  0.26.1 (OK)
qtconsole >=4.2.0:  4.3.1 (OK)
IPython >=4.0    :  6.1.0 (OK)
pylint >=0.25    :  1.7.4 (OK)
```



Discussion:
Thanks for reporting. We'll try to fix this in a future release.

Resolving patch:
diff --git a/spyder/plugins/help.py b/spyder/plugins/help.py
--- a/spyder/plugins/help.py
+++ b/spyder/plugins/help.py
@@ -834,9 +834,12 @@ def load_history(self, obj=None):
 
     def save_history(self):
         """Save history to a text file in user home directory"""
-        open(self.LOG_PATH, 'w').write("\n".join( \
-                [to_text_string(self.combo.itemText(index))
-                 for index in range(self.combo.count())] ))
+        try:
+            open(self.LOG_PATH, 'w').write("\n".join( \
+                    [to_text_string(self.combo.itemText(index))
+                     for index in range(self.combo.count())] ))
+        except (UnicodeDecodeError, EnvironmentError):
+            pass
 
     @Slot(bool)
     def toggle_plain_text(self, checked):


Test patch: