in Education by
UnicodeEncodeError: 'ascii' codec can't encode character u'\xa0' in position 20: ordinal not in range(128) Currently I am working on this code: customer_telno = customer.find('div', 'customer_phone_number') customer_telno = '' if customer_telno is None else customer_telno.contents[0] p.customer_info = str(customer_phone + ' ' + customer_telno).strip() When the above snippet is run I get UnicodeEncodeError : Traceback (most recent call last): File "foobar.py", line 792, in p.customer_info = str(customer_phone + ' ' + customer_telno).strip() UnicodeEncodeError: 'ascii' codec can't encode character u'\xa0' in position 20: ordinal not in range(128) I have tried using everything possible but couldn’t find anything which works consistently. Can anyone solve this problem?

1 Answer

0 votes
by
This error is occurring mainly because you are converting unicode to encoded bytes using str, so to solve the problem you need to stop str and instead use .encode() to properly encode the strings. Syntax- str.encode(encoding="utf-8",errors="strict") It returns a encoded version of a string as a bytes object. Here, an error is set to specify different error handling scheme and by default, the error is set to “strict” which means that the encoding error raises a UnicodeError, the default encoding is set to “utf-8”. Using .encode() in your code: p.customer_info = u' '.join((customer_phone, customer_telno)).encode('utf-8').strip()

Related questions

0 votes
    Currently I am working on this code: customer_telno = customer.find('div', 'customer_phone_number') customer_telno = ... this problem? Select the correct answer from above options...
asked Jan 22, 2022 in Education by JackTerrance
0 votes
    Which of the following is not a valid encoding scheme for character?a. ASCII b. ISCII c. Unicode and. ASCII Select the correct answer from above options...
asked Dec 25, 2021 in Education by JackTerrance
0 votes
    I moved a web app that was using 1.8.7 to 1.9.2 and now I keep getting incompatible character ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 2, 2022 in Education by JackTerrance
0 votes
    1 65 101 20 Select the correct answer from above options C-Language questions and answers, C-Language questions ... and answers pdf, C-Language interview questions for beginners...
asked Oct 26, 2021 in Education by JackTerrance
0 votes
    I'm porting functionality from an Objective-C iPhone app to a Javascript iPhone app (Appcelerator Titanium). ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 4, 2022 in Education by JackTerrance
0 votes
    I am trying to create a "feature branch" from golang. The following code is not working: reader : ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 9, 2022 in Education by JackTerrance
0 votes
    Question 15: 15. .is a type of response test used in computing as an attempt to ensure that the response is ... code c) New code Select the correct answer from above options...
asked Dec 15, 2021 in Education by JackTerrance
0 votes
    Closed. This question needs details or clarity. It is not currently accepting answers. Want to improve this ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 23, 2022 in Education by JackTerrance
0 votes
    MapReduce jobs submitted from either Oozie, Pig or Hive can be used to encode, improve and sample the data sets ... of R Programming Select the correct answer from above options...
asked Feb 12, 2022 in Education by JackTerrance
0 votes
    Let's say I have a JSON set of events, each with a start time and end time, and I need to ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 17, 2022 in Education by JackTerrance
0 votes
    If I use a while loop for my below code, it is not giving the desired output, but when i use for loop i am anle ... x += 1 print(Comm) Select the correct answer from above options...
asked Jan 9, 2022 in Education by JackTerrance
0 votes
    Construct logical expressions to represent the following conditions a) salary is not in the range 2500 to 5000 Select the correct answer from above options...
asked Dec 11, 2021 in Education by JackTerrance
0 votes
    Course Results (${courseResponseList.getCourses().size()}) Want to show above div. jquery script. jQuery. ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 6, 2022 in Education by JackTerrance
0 votes
    Course Results (${courseResponseList.getCourses().size()}) Want to show above div. jquery script. jQuery. ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 20, 2022 in Education by JackTerrance
0 votes
    I am using simple thread to execute the httpGet to server when a button is clicked, but I get ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 16, 2022 in Education by JackTerrance
...