好吧,我有一些似乎无法正常工作的旧 python 代码,我已经研究到互联网的尽头,试图找到一个修复程序。
def getURL(self, context):
# Make this an absolute URL- currently it's required for
# links placed in the RSS and XML feeds, and won't
# hurt elsewhere.
req = context['request']
port = req.host[2]
hostname = req.getRequestHostname()
if req.isSecure():
default = 443
else:
default = 80
if port == default:
hostport = ''
else:
hostport = ':%d' % port
path = posixpath.join('/stats',
*(tuple(self.target.pathSegments) + self.relativePathSegments))
return quote('http%s://%s%s%s' % (
req.isSecure() and 's' or '',
hostname,
hostport,
path), "/:")
现在我认为这只是context['request']
给我问题,但我不确定。此代码块来自CIA.vc 项目(确切地说是link.py),所以如果有什么没有意义的地方,请检查那里
我从 python 得到的第一个错误也是:
File "/home/justasic/cia/cia/LibCIA/Web/Stats/Link.py", line 41, in getURL port = req.host[2]
exceptions.TypeError: unindexable object
但是在我发现我认为是一个简单的修复后,我得到了更多关于context['request']
未定义的信息