If I build a barebone, it's working nicely. But in my actual code, I receive an Unicode related error.
temp_url = "http://search.jd.com/Search?keyword=" + quote(self.keywords)
File "/usr/lib/python3.5/urllib/parse.py", line 706, in quote string = string.encode(encoding, errors)
UnicodeEncodeError: 'utf-8' codec can't encode character '\udce8' in position 0: surrogates not allowed
I'm using an argument to pass my search string to Scrapy (1.4):
scrapy crawl jdspider -a keywords="电灯"
and the relevant code looks like:
# -*- coding: utf-8 -*-
import scrapy, re
from urllib.parse import quote
def __init__(self, keywords=''):
self.keywords = keywords.strip()
temp_url = "http://search.jd.com/Search?keyword=" + quote(self.keywords)
print ( temp_url )
So the print won't even get executed - sth. doesn't work with the quote method.
Python 3.5.2 Scrapy 1.4.0 Kubuntu 16.04
What am I doing wrong?