파이썬 코딩 초보자입니다.이 코드는 제 코드이며 오류를 해결할 수 없습니다. 어떤 사람이 실제로 코드에서 prob가 무엇인지 제안 할 수 있습니까? 미리 감사드립니다.TypeError : 파이썬에서 'str'및 'builtin_function_or_method'객체를 연결할 수 없습니다.
import urllib2
username = '<YOUR USERNAME>'
password = '<YOUR PASSWORD>'
format = 'json' # json or xml
filename = 'archive.json' # filename of the archive
tweets = 164 # number of tweets
pages = (int(float(tweets)/float(80)))+1
auth = urllib2.HTTPPasswordMgrWithDefaultRealm()
auth.add_password(None, 'http://twitter.com/account/', username, password)
authHandler = urllib2.HTTPBasicAuthHandler(auth)
opener = urllib2.build_opener(authHandler)
urllib2.install_opener(opener)
i = 1
response = ''
print 'Downloading tweets. Note that this may take some time'
while i <= pages:
request = urllib2.Request('http://twitter.com/statuses/user_timeline/account.' \
+ format + '?page=' + str(i))
response = response + urllib2.urlopen(request).read()
i = i + 1
handle = open(filename,"w")
handle.write(response)
handle.close()
print 'Archived ' + str(tweets) + ' of ' + username + \
'\'s tweets to ' + filename
오류는 다음과 같이이다 :
**Traceback (most recent call last):
File "<pyshell#14>", line 3, in <module>
+ format + '?page=' + str(i))
TypeError: cannot concatenate 'str' and 'builtin_function_or_method' objects**
'format'은 내장 함수입니다. 확실히 문자열로 다시 지정 했습니까? 가장 좋은 해결책은 다른 변수 이름을 사용하는 것입니다. –
나는 그것을했다. 그러나 나에게 그 아래에 명시된 오류를 보여주고있다 ... 무단 401 종류. –
이것은 전적으로 관련이 없지만 오류는 아주 자명합니다. 직접 디버깅 해보고 문제가 발생하면 최소한의 자체 포함 코드 샘플을 사용하여 문제를 재현하는 새로운 질문을 엽니 다. –