Найти - Пользователи
Полная версия: TypeError: can't use a string pattern on a bytes-like object
Начало » Python для новичков » TypeError: can't use a string pattern on a bytes-like object
1
GrayCardinal
Добрый день !
Первая прога на питоне, не пинайте сильно.
Вот этот код не работает :(
import urllib.request
import re

class Travian:
def __init__():
pass

def loginPage(self):
data = urllib.request.urlopen("http://" + self.server)
data = data.read()
return data

def loginForm(self):
lp = self.loginPage()
re.search("<form.*?<\/form>", lp, re.M)

def login(self, user, password):
lf = self.loginForm()
pass

class Main(Travian):
def __init__(self):
self.server = "speed.travian.ru"

def start(self):
self.login("", "")


m = Main()
m.start()
ВЫДАЁТ
Traceback (most recent call last):
File "./main.py", line 32, in <module>
m.start()
File "./main.py", line 28, in start
self.login("", "")
File "./main.py", line 20, in login
lf = self.loginForm()
File "./main.py", line 17, in loginForm
re.search("<form.*?<\/form>", lp, re.M)
File "/opt/python3//lib/python3.0/re.py", line 157, in search
return _compile(pattern, flags).search(string)
TypeError: can't use a string pattern on a bytes-like object
Версия Python - 3.0 OS- openSUSE linux
Как лечить ?

Заранее благодярю…
Олег.
slivlen
Приведи lp к строке.
GrayCardinal
slivlen
Как ?
slivlen
lp = lp.decode() или lp = str(lp)
GrayCardinal
БЛАГОДАРЮ !
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB