logo
Tags down

shadow

Response [412] when using the requests python package to access this webpage, how to get around it?


By : Bruce Huang
Date : September 15 2020, 01:00 PM
wish help you to fix your issue That website require a valid Cookie in order to response back to you.
I've tried several ways such as calling the main website and then retrieving the Cookie under requests.Session() but the website is not allowing me to pass through.
code :
import requests

headers = {
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:72.0) Gecko/20100101 Firefox/72.0",
    "Cookie": "Hm_lvt_5544783ae3e1427d6972d9e77268f25d=1578572654; Hm_lpvt_5544783ae3e1427d6972d9e77268f25d=1578572671; dataHide2=64fa0f2a-a6aa-43b4-adf0-ce901e8d1a37; FSSBBIl1UgzbN7N80S=sXE0qXcyGkTm4uVerLqfZyUU3XFMZzkm22k.eqVABLPe0eYMo3D8uX5ZJ07.7cCr; FSSBBIl1UgzbN7N80T=4aY.P74ZFvDef6i1BgsPAGpjsGOCcIHJFaOyshl4_fJ1WvTk1nqBkdG9PsyX3VRZcIuI8zdYiRJw4rEBQfx.Mv.GS_wT6Hzgiw.AY.UMP.Mw4iCKXGDzY1UeIH2gUd15impxzBVzZpN3MnSdqD0TUqcxSq0RrvIuE8RKT5pFLAqaNnVqtbeSACx43yIYtKJ41y8Isu6a6lNOlWNeaFJ8bx22pKm3lAIO.HIDhGSZqrUP76.q3i4Iux59f7dqJPuSRF90G1LSUBE8t8HrlWzBcSwJJJARX4Ioc0iHmHvdkVoigUitTRjLUHJM4ieOV1sLBDsq"
}

r = requests.get("http://wjw.hubei.gov.cn/", headers=headers)
print(r)
<Response [200]>
import requests

headers = {
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:72.0) Gecko/20100101 Firefox/72.0"}

with requests.Session() as req:
    r = req.get("http://www.hubei.gov.cn/")
    headers['Cookie'] = r.headers.get("Set-Cookie")
    for item in range(10):
        new = req.get("http://wjw.hubei.gov.cn/", headers=headers)
        print(new)


Share : facebook icon twitter icon

How do I make the response from Python's requests package be a "file-like object"


By : user2110866
Date : March 29 2020, 07:55 AM
hop of those help? You could use the response.raw file object, but take into account that any content encoding (such as GZIP or Deflate compression) will still be in place unless you set the decode_content flag to True when calling .read(), which psycopg2 will not.
You can set the flag on the raw file object to change the default to decompressing-while-reading:
code :
response.raw.decode_content = True

How to access server response when Python requests library encounters the retry limit


By : Ni KA
Date : March 29 2020, 07:55 AM
I wish this helpful for you Checking out the urllib3 source, I discovered that the Retry object takes a named parameter called raise_on_status. True is the default. When set to False, running into the retry limit causes a response to be returned instead of an exception being thrown. The code below shows me causing an HTTPError (containing the Response) to be thrown by using the raise_for_status method on the Response, but one could just as easily use the Response directly.
code :
#!/usr/bin/env python

import requests
from requests.adapters import HTTPAdapter
from requests.packages.urllib3.util.retry import Retry
from requests.exceptions import HTTPError


def main():
    retry_policy = Retry(
        total=3,
        status_forcelist=[418],
        raise_on_status=False)

    session = requests.Session()
    session.mount('http://', HTTPAdapter(max_retries=retry_policy))

    try:
        response = session.get('http://httpbin.org/status/418')
        response.raise_for_status()
    except HTTPError as e:
        print e.response.status_code
        print e.response.content


if __name__ == '__main__':
    main()
418

-=[ teapot ]=-

   _...._
 .'  _ _ `.
| ."` ^ `". _,
\_;`"---"`|//
  |       ;/
  \_     _/
    `"""`

Empty response after submit a form with (requests) python package


By : shalman
Date : March 29 2020, 07:55 AM
it fixes the issue If You check request data using Firebug or some similar tool, You'd see that request data is actually in following format:
code :
-----------------------------41184676334
Content-Disposition: form-data; name="email"

a.nobody@here.ac.uk
-----------------------------41184676334
Content-Disposition: form-data; name="tagset"

c7
-----------------------------41184676334
Content-Disposition: form-data; name="style"

xml
-----------------------------41184676334
Content-Disposition: form-data; name="text"

TEST
-----------------------------41184676334--

Python Requests package: Handling xml response


By : Mohammad Mahjoub
Date : March 29 2020, 07:55 AM
may help you . requests does not handle parsing XML responses, no. XML responses are much more complex in nature than JSON responses, how you'd serialize XML data into Python structures is not nearly as straightforward.
Python comes with built-in XML parsers. I recommend you use the ElementTree API:

How can I access a peer's cert chain from a python-requests response/exception object?


By : Pedro Célestin
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , Take requests.get("https://151.101.1.69") # stackoverflow's ip as an example:
code :
try:
    requests.get("https://151.101.1.69")
except requests.exceptions.SSLError as e:
    cert = e.args[0].reason.args[0]._peer_cert
try:
    requests.get("https://fpslinux1.finalphasesystems.com/")
except requests.exceptions.SSLError:
    import ssl
    import OpenSSL
    cert = ssl.get_server_certificate(('fpslinux1.finalphasesystems.com', 443))
    cert = OpenSSL.crypto.load_certificate(OpenSSL.crypto.FILETYPE_PEM, cert)
    print(cert.get_issuer())
    print(cert.get_subject().get_components())
Related Posts Related Posts :
  • Why can't I run a .py file that only has a print function?
  • How can I generate an array of 8 unique numbers in python?
  • How to click on an element identical to another element using selenium in python?
  • UsageError: Line magic function `%tensorflow_version` not found
  • Merge two sorted linked lists - Python implementation - wrong/incomplete output
  • Python: proper list comprehension syntax and how to not end up with a list of booleans
  • Why naked Python decorators (without @) do not generate compiler error?
  • Other ways to remove commas in a row of a given column
  • Program written with asyncio takes same time to run as the synchronous version
  • RNN : understanfingConcatenating layers
  • Convert DatetimeWithNanoseconds to date format in python firestore
  • Estimating pi with a Monte Carlo method results in a larger value than expected
  • Create subsets from Python list with suffix
  • How to merge first part of a list value prior to a character, based on the values after the character in python
  • Python, finding item in a list with variables
  • remove demarcation from text image - image processing
  • Cannot create a new environment or install libraries in Ananconda
  • Finding whether a sentence is positive, neutral or negative?
  • Reading license plate from image using OpenCV Python and Tesseract
  • how to run odoo combuted field on all records?
  • path is not reading unless it is in order
  • How to Create a DataFrame with Loops?
  • Displaying the occurrences in a Histogram with tkinter
  • Simulate Fourier Analysis with Python
  • Is there an elegant way to call a list of methods on the same object in Python?
  • When do we need socket and when do we need request?
  • Google Foobar challenge Power Hungry - failing test no. 3 [hidden] out of 5 test cases?
  • Pandas vs Numpy indexing: Why this fundamental difference in ordering of indices?
  • ImportError: cannot import name 'mylist' from 'mymodule'
  • Minesweeper: Reveal Surrounding Blocks Function Freezes
  • Python iterate through connected components in grayscale image
  • LinkedList delete functionality is deleting 2 nodes
  • Minesweeper Reveal Element Python
  • Discord.py bot not using proper text formatting in embeds, but only on mobile?
  • str() doesn't work in the body of my function
  • How to search a list with nested dictionary by dictionary value, returning the index of the list with the dictionary ele
  • Python requests, get() without a protocol?
  • How to run a Python code inside a custom package?
  • Can we filter dictionary based on 'id' in python?
  • Normalization before clustering
  • How to define the name of the model in a function
  • PyTorch CNN: Loss is unchanging
  • Plot square signal from binary array [1, 0, 1, 0, 0, 1, 0, 1, 1, 1, 0, 1]?
  • Something is turning my lambda function into def function when I run, how do i solve this?
  • Redisearch aggregate return top 5 of each group
  • How can i save a list/matrix in binary format in KDB?
  • Python coding for GPU
  • Extract value of name in pandas
  • How to get the value of a key value pair from a dictonary which is inside a list and where key starts with a very specif
  • Best place to work together on a python project?
  • DynamoDB - avoid data overwrite with primary partition key remaining the same for all data points
  • Appending (not replacing) items in a nested dictionary via a list of keys
  • Flask Post is not coming to the Same Page
  • TypeError: cannot concatenate 'str' and 'tuple' objects in python 2.7
  • How to split a field within Python and return value in another column?
  • Tkinter + matplot animation filling memory
  • Is it possible for a python file to write another python file?
  • How to use cumsum function group wise in a loop using python
  • Tweepy StreamListener: Tweet when a specified account Tweets
  • Arrange and find most appeared item in the list
  • shadow
    Privacy Policy - Terms - Contact Us © 35dp-dentalpractice.co.uk