2014-09-22 20 views
6
for comment_entry in comment_feed.entry: 
content = comment_entry.ToString() 
parse = BeautifulSoup(content) 
for con in parse.find('ns0:content'): 
    print con.string 
    s = con.string 
    file.write(s.encode('utf8')) 

Hata vardır:AttributeError sorununu giderme: 'NoneType' nesne piton hiçbir özelliği 'ni kodlamak' Ben alıyorum

File "channel_search.py", line 108, in youtube_search 
file.write(s.encode('utf8')) 
AttributeError: 'NoneType' object has no attribute 'encode' 
+0

print con.string size ne verir –

cevap

5

Sizin s olabilir NoneType

deneyin
s = con.string 
if s:file.write(s.encode('utf8')) 
# or if s is not None   
#if you want to check only for None   
+0

@dav boş dize dönüştürme idizm hiçbir anlamı yoktur? . Yani her iki şey için de verilenden geçerli değildir. –

İlgili konular