开发者

Python error when retrieving a url from a database and opening it with webbrowser()

开发者 https://www.devze.com 2023-04-05 10:28 出处:网络
I am trying to make an app similar to StumbleUpon using Python as a back end for a personal project . From the database I retrieve a website name and then I open that website with webbrowser.open(\"ht

I am trying to make an app similar to StumbleUpon using Python as a back end for a personal project . From the database I retrieve a website name and then I open that website with webbrowser.open("http://www.website.com"). Sounds pretty straight forward right but there is a problem. When I try to open the website with webbrowser.open("website.com") it returns the following error:

File "fetchall.py", line 18, in <module>
webbrowser.open(x)
File "/usr/lib/python2.6/webbrowser.py", line 61, in open
if browser.open(url, new, autoraise):
File "/usr/lib/python2.6/webbrowser.py", line 190, in open
for arg in self.args]
TypeError: expected a character buffer object

Here is my code:

import sqlite3
import webbrowser 

conn = sqlite3.connect("websites.sqlite")

cur = conn.cursor()

cur.execute("SELECT WEBSITE FROM COLUMN")

x = cur.fetchmany(1)

webbrowser.open(x)

EDIT

Okay thanks fo开发者_如何学Pythonr the reply, but now I'm receiving this: "Error showing URL: Error stating file '/home/user/(u'http:bbc.co.uk,)': No such file or directory".

What's going on ?


webbrowser.open is expecting a character buffer, but fetchmany returns a list. So webbrowser.open(x[0]) should do the trick.

0

精彩评论

暂无评论...
验证码 换一张
取 消