\xa0
is Non-breaking space which is shown as a simple space in a web-page. Is code is A0
which is outside of of ASCII range (0-127):
Python 2.7.6 (default, Mar 22 2014, 22:59:56)
>>> u'Rs.\xa05,000\n\r\n\t\t\t\t\t / -'.encode()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
UnicodeEncodeError: 'ascii' codec can't encode character u'\xa0' in position 3: ordinal not in range(128)
So you have to manually replace it with a simple space, before encoding it to ASCII.
Be default str.strip
strips only whitespace, so you should manually strip chars / -
.
This should work:
>>> u'Rs.\xa05,000\n\r\n\t\t\t\t\t / -'.replace(u'\xa0', u' ').encode().rstrip('-/ ').strip()
'Rs. 5,000'
>>>