Changes to get private server working with user/pass. Added additional header to req in lib/musicbrainz2/webservice.py, some small changes to mb.py

This commit is contained in:
rembo10
2012-03-19 09:16:04 +00:00
parent 7cedd07985
commit 4775151409
3 changed files with 15 additions and 16 deletions

View File

@@ -453,7 +453,7 @@
<div id="hpserveroptions">
<h3>Username:<br><input type="text" name="hpuser" value="${config['hpuser']}" size="20"></h3>
<h3>Password:<br><input type="password" name="hppass" value="${config['hppass']}" size="15"></h3>
<i class="smalltext2"><a href="http://headphones.codeshy.com">what is this?</a></p>
<i class="smalltext2"><a href="http://headphones.codeshy.com/vip">Get an Account</a></p>
</div>
</table>
</div>

View File

@@ -20,9 +20,8 @@ mb_lock = threading.Lock()
# being used, so we can send those values to the log
def startmb(forcemb=False):
# just in case someone switches to the headphones server mid-query
hpuser=None
hppass=None
mbuser = None
mbpass = None
if forcemb or headphones.MIRROR == "musicbrainz.org":
mbhost = "musicbrainz.org"
@@ -33,25 +32,20 @@ def startmb(forcemb=False):
mbport = headphones.CUSTOMPORT
sleepytime = headphones.CUSTOMSLEEP
elif headphones.MIRROR == "headphones":
mbhost = "178.63.142.150"
mbport = 5000
mbhost = "codeshy.com"
mbport = 3333
mbuser = headphones.HPUSER
mbpass = headphones.HPPASS
sleepytime = 0
hpuser = headphones.HPUSER
hppass = headphones.HPPASS
else:
mbhost = "tbueter.com"
mbport = 5000
sleepytime = 0
service = ws.WebService(host=mbhost, port=mbport)
service = ws.WebService(host=mbhost, port=mbport, username=mbuser, password=mbpass, mirror=headphones.MIRROR)
q = ws.Query(service)
logger.debug('Using the following server values:\nMBHost: %s ; MBPort: %i ; Sleep Interval: %i ' % (mbhost, mbport, sleepytime))
if headphones.MIRROR == "headphones" and not forcemb:
try:
logger.debug('Headphones Username: %s ; Headphones Password: %s%s%s' % (hpuser, hppass[0],(len(hppass)-2) * '*', hppass[-1]))
except Exception, e:
logger.debug('Error logging hpuser or hppass: %s. Check your settings' % e)
return (q, sleepytime)
@@ -177,7 +171,7 @@ def getArtist(artistid, extrasonly=False):
artist = q.getArtistById(artistid, inc)
break
except WebServiceError, e:
logger.warn('Attempt to retrieve artist information from MusicBrainz failed for artistid: %s. Sleeping 5 seconds' % artistid)
logger.warn('Attempt to retrieve artist information from MusicBrainz failed for artistid: %s. Sleeping 5 seconds: %s' % (artistid, e))
attempt += 1
time.sleep(5)

View File

@@ -17,6 +17,7 @@ __revision__ = '$Id: webservice.py 12973 2011-04-29 11:49:31Z luks $'
import re
import urllib
import urllib2
import base64
import urlparse
import logging
import os.path
@@ -191,7 +192,7 @@ class WebService(IWebService):
def __init__(self, host='musicbrainz.org', port=80, pathPrefix='/ws',
username=None, password=None, realm='musicbrainz.org',
opener=None):
opener=None, mirror=None):
"""Constructor.
This can be used without parameters. In this case, the
@@ -212,6 +213,7 @@ class WebService(IWebService):
self._realm = realm
self._pathPrefix = pathPrefix
self._log = logging.getLogger(str(self.__class__))
self._mirror = mirror
if opener is None:
self._opener = urllib2.build_opener()
@@ -249,6 +251,9 @@ class WebService(IWebService):
userAgent = 'python-headphones/' + musicbrainz2.__version__
req = urllib2.Request(url)
req.add_header('User-Agent', userAgent)
if self._mirror == 'headphones':
base64string = base64.encodestring('%s:%s' % (self._username, self._password)).replace('\n', '')
req.add_header("Authorization", "Basic %s" % base64string)
return self._opener.open(req, data)