I used the requests.get()
method when writing a crawler in python :
DEF OpenURL (URL, IP, Agent): # function parameter is url: web page address; ip: ip pool; agent: User-Agent, three are string type requests.get (url, headers = agent, proxies = ip)
What is puzzled is that the’str’ object has no attribute’get’ error was reported when using it
After reviewing the documentation, it was found that the headers and proxies parameters in the get() method should be passed in a dictionary instead of a string , so after modification, the code runs successfully:
def openUrl(url, ip, agent): headers = { ' User-Agent ' : agent} proxies = { ' http ' : ip} requests.get(url, headers =headers, proxies=proxies)
Similar Posts:
- Windows: SSH-add Error connecting to agent: No such file or directory [Solved]
- [Solved] HTTP Error 301: The HTTP server returned a redirect error that would lead to an infinite loop.
- [Solved] HttpClient HttpRequestHeaders.From Error: The specified value is not a valid ‘From’ header string.
- Differences of urllib, urllib2, httplib and httplib2 libraries in Python
- Summary of SSH error reporting and solution records
- failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found
- Unable to open thread: http request failed! (4 pesos, PHP 4)
- [Solved] Python request Error: requests.exceptions.ReadTimeout: HTTPSConnectionPool (xxxx)
- Complete failure: http request failed!
- Git Add The Public Key sign_and_send_pubkey: signing failed: agent refused operation