2016-04-24 5 views
-1

Suche nach einem Weg UnicodeEncodeError zu lösen: 'ascii' Codec nicht Zeichen u in Position '\ u2019' kodieren, können 4: ordinal nicht in Reichweite (128)Robot Framework ASCII-Code Encoding

Derzeit ist mein Code:

coding: utf-8 
*** Settings *** 
Documentation This is a simple test with Robot Framework 
Suite Setup  Connect To Database pymysql ${DBName} ${DBUser} ${DBPass} ${DBHost} ${DBPort} 
Suite Teardown Disconnect From Database 
Library   Selenium2Library 
Library   DatabaseLibrary 
Library   OperatingSystem 
Library   String 

*** Variables *** 
${DBHost}   localhost 
${DBName}   robottest 
${DBPass}   sahill 
${DBPort}   3306 
${DBUser}   sahill 

*** Test Cases *** 
Open Browser To Start Roboting 
    [Documentation] Sarting robot 
    [Tags] Smoke 
    Open Browser http://movieplus.cc/a-z-movies/ firefox 
    Maximize Browser Window 
    WAIT UNTIL PAGE CONTAINS have any legal issues please contact appropriate media file owners/hosters. 

    Click Element xpath=//div[@class='wrapper']//div[@class='thumbs']//div[@class='wrap']//div[1]//a 
    WAIT UNTIL PAGE CONTAINS have any legal issues please contact appropriate media file owners/hosters. 
    ${count} = Get Matching Xpath Count  xpath=//div[@class='wrap_content']//ul[@class='list']//li 
    ${title} = get text xpath=//div[@class='wrap_content']//h2[@class='title']//span[@class='color'] 
    ${cate} = get text xpath=//div[@class='wrap_content']//ul[@class='list'] 
    ${director} = get text xpath=//div[@class='wrap_content']//div[1]//span[@class='desc'] 
    ${cast} = get text xpath=//div[@class='wrap_content']//div[2]//span[@class='desc'] 
    ${content} = get text xpath=//div[@class='wrap_content']//div[3]//span[@class='description']//p 
    ${image_link} =  Get element attribute xpath=//div[@class='content']//div[@class='wrap_img']//[email protected] 
    Execute SQL String  INSERT INTO test VALUES('${title}', '${cate}', '${director}', '${cast}','${content}', '${image_link}', 'link'); 
    Go Back 

in ${content} Variable dieser Inhalt speichern

A young woman wakes up in the basement of a man who claims he saved her life after pulling her from her overturned car which violently crashed along the highway. The man states that the world above them is no longer safe and is now a danger zone that threatens the rest of humanity. With no knowledge of what actually lies above and trust running thin between them, the woman questions **what’s true and what’s not**. Is the man a delusional psychotic that has a more sinister agenda for her? Or is it really hell on earth above ground like he swears? 
+1

Verwenden Sie Python 2 oder Python 3? – user312016

+0

Python 2, mit Python 3 Roboter-Framework funktioniert nicht – Sahill

+0

Ich habe meine Antwort bearbeitet. – user312016

Antwort

0

Sie verwenden python 2, so, Sie Problem ist, dass Sie nicht eine richtige Codierung zu Beginn Ihrer Datei definiert haben.

# coding: utf-8 

Sie haben die Wahl:

  • die Header-Codierung Setzen Sie am Anfang der Datei
  • oder:

    Use an ascii character for "’", like "'" 
    
+0

Vielen Dank für Ihre Antwort, im Grunde mache ich ein System, in dem ich Inhalt mit Roboter-Framework bekommen Text Keyword von einer Website, in diesem Fall bin nicht in der Lage zu ändern '' ' – Sahill

+0

@Sahill This ist nicht das, was ich in deinem Code sehe, könntest du es aktualisieren, um ein ähnliches Beispiel aus der realen Welt zu erhalten? – user312016

+0

Sehr geehrter Herr, ich aktualisiere meine Frage und jetzt sehen Sie alle meine Code – Sahill

0

Bevor die SQL-Zeichenfolge ausführen Sie können den Inhalt wie folgt codieren:

${content} = Encode String To Bytes ${content} ASCII errors=replace 

In diesem Fall ist das Ergebnis: ... the woman questions what?s true and what?s not. Is the ...

Wenn Sie die Fehler ignorieren:

${content} = Encode String To Bytes ${content} ASCII errors=ignore 

Das Ergebnis wird sein: ... the woman questions whats true and whats not. Is the ...

(was verständlicher sein wird)