python-requests

AttributeError: 'xml.etree.ElementTree.Element' object has no attribute 'encode'

断了今生、忘了曾经 提交于 2021-02-09 07:42:21
问题 I'm trying to make a desktop notifier, and for that I'm scraping news from a site. When I run the program, I get the following error. news[child.tag] = child.encode('utf8') AttributeError: 'xml.etree.ElementTree.Element' object has no attribute 'encode' How do I resolve it? I'm completely new to this. I tried searching for solutions, but none of them worked for me. Here is my code: import requests import xml.etree.ElementTree as ET # url of news rss feed RSS_FEED_URL = "http://www

AttributeError: 'xml.etree.ElementTree.Element' object has no attribute 'encode'

南楼画角 提交于 2021-02-09 07:30:34
问题 I'm trying to make a desktop notifier, and for that I'm scraping news from a site. When I run the program, I get the following error. news[child.tag] = child.encode('utf8') AttributeError: 'xml.etree.ElementTree.Element' object has no attribute 'encode' How do I resolve it? I'm completely new to this. I tried searching for solutions, but none of them worked for me. Here is my code: import requests import xml.etree.ElementTree as ET # url of news rss feed RSS_FEED_URL = "http://www

AttributeError: 'xml.etree.ElementTree.Element' object has no attribute 'encode'

不想你离开。 提交于 2021-02-09 07:26:44
问题 I'm trying to make a desktop notifier, and for that I'm scraping news from a site. When I run the program, I get the following error. news[child.tag] = child.encode('utf8') AttributeError: 'xml.etree.ElementTree.Element' object has no attribute 'encode' How do I resolve it? I'm completely new to this. I tried searching for solutions, but none of them worked for me. Here is my code: import requests import xml.etree.ElementTree as ET # url of news rss feed RSS_FEED_URL = "http://www

AttributeError: 'xml.etree.ElementTree.Element' object has no attribute 'encode'

烈酒焚心 提交于 2021-02-09 07:26:21
问题 I'm trying to make a desktop notifier, and for that I'm scraping news from a site. When I run the program, I get the following error. news[child.tag] = child.encode('utf8') AttributeError: 'xml.etree.ElementTree.Element' object has no attribute 'encode' How do I resolve it? I'm completely new to this. I tried searching for solutions, but none of them worked for me. Here is my code: import requests import xml.etree.ElementTree as ET # url of news rss feed RSS_FEED_URL = "http://www

Filling out a website form using Python requests

独自空忆成欢 提交于 2021-02-09 05:44:26
问题 I'm trying to programmatically fill out a form on a page using Python requests. I wrote some code to do that: #!/usr/bin/python import requests URL = 'https://www.acgov.org/ptax_pub_app/RealSearch.do' payload = { 'displayApn': '1-123-1', 'showHistory': 'y', } s = requests.session() r = s.post(URL, data=payload) print r.status_code print r.cookies print r.text However, the output isn't coming out as expected. The status code returned is 200 The cookies are printing out as <RequestsCookieJar[]>

Filling out a website form using Python requests

非 Y 不嫁゛ 提交于 2021-02-09 05:44:11
问题 I'm trying to programmatically fill out a form on a page using Python requests. I wrote some code to do that: #!/usr/bin/python import requests URL = 'https://www.acgov.org/ptax_pub_app/RealSearch.do' payload = { 'displayApn': '1-123-1', 'showHistory': 'y', } s = requests.session() r = s.post(URL, data=payload) print r.status_code print r.cookies print r.text However, the output isn't coming out as expected. The status code returned is 200 The cookies are printing out as <RequestsCookieJar[]>

Python download image with lxml

情到浓时终转凉″ 提交于 2021-02-08 15:48:11
问题 I need to find an image in a HTML code similar to this one: ... <a href="/example/1"> <img id="img" src="http://example.net/example.jpg" alt="Example" /> </a> ... I am using lxml and requests. Here is the code: import lxml from lxml import html import requests url = 'http://www.example.com' r = requests.get(url) tree = lxml.html.fromstring(r.content) img = tree.get_element_by_id("img") f = open("image.jpg",'wb') f.write(requests.get(img['src']).content) But i am getting an error: Traceback

How to extract the HTTP error text from a requests response?

旧时模样 提交于 2021-02-08 12:33:11
问题 I have the following code: tries = 10 for n in range(tries): try: .... responsedata = requests.get(url, data=data, headers=self.hed, verify=False) responsedata.raise_for_status() .. if .... : break #exit loop condition except (ChunkedEncodingError, requests.exceptions.HTTPError) as e: print ("page #{0} run #{1} failed. Returned status code {2}. Msg: {3}. Retry.".format(page, n, responsedata.status_code, sys.exc_info()[0])) if n == tries - 1: raise e # exit the process The prints I see are:

Python requests base64 image

旧街凉风 提交于 2021-02-08 12:21:14
问题 I am using requests to get the image from remote URL. Since the images will always be 16x16, I want to convert them to base64 , so that I can embed them later to use in HTML img tag. import requests import base64 response = requests.get(url).content print(response) b = base64.b64encode(response) src = "data:image/png;base64," + b The output for response is: response = b'GIF89a\x80\x00\x80\x00\xc4\x1f\x00\xff\xff\xff\x00\x00\x00\xff\x00\x00\xff\x88\x88"""\xffff\... The HTML part is: <img src="

Python requests with login credentials

安稳与你 提交于 2021-02-08 11:43:00
问题 I am trying to login to a URL & download the content then parse, the URL needs username & password to login. using below gives below errors: import requests url = 'https://test/acx/databaseUsage.jssp?object=all' values = {'username': 'test_user', 'password': 'test_pswd'} headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36'} r = requests.post(url, data=values, headers=headers) print r.content Error