http-headers

flask send base 64 encoded pdf string without saving

flask send base 64 encoded pdf string without saving Question: I have a flask application. I am using selenium cdp commands to generate pdfs. I get a base64 encoded string from selenium. Before sending the response as a pdf I save the file in my filesystem. file.write(base64.b64decode(pdf_string[‘data’]) And the response is just send_file(‘path’, ‘name.pdf’) How …

Total answers: 2

Request headers to scrape pypi.org

Request proxies to access PyPI Question: I am trying to screenscrape PyPI packages using the requests library and beautiful soup – but am met with an indefinite hang. I am able to retrieve html from a number of sites with: session = requests.Session() session.trust_env = False response = session.get("http://google.com") print(response.status_code) i.e. without providing headers. I …

Total answers: 4

RavenPack API_key is working in postman but NOT in python code

RavenPack API_key is working in postman but NOT in python code Question: I am tryin to work with this repo https://github.com/RavenPack/python-api Weirdly enough, the API is working perfectly with POSTMAN (it’s a tool used to automate testing API development and HTTP calls) Here’s the code snippet from ravenpackapi import RPApi from ravenpackapi import Dataset api …

Total answers: 2

How to export offer file from Bol Retailer API using Python

How to export offer file from Bol Retailer API using Python Question: I have been trying to export offer file using Python for Bol Retailer API According to the official docs on request an offer file export I have include all the headers and formats but it throws a 400 Bad Request 400 Bad Request …

Total answers: 1

Beautiful Soup fails to acquire prices from amazon at times

Beautiful Soup fails to acquire prices from amazon at times Question: In running a beautiful soup script, to acquire prices from amazon. I’ve stumbled across a problem where beautiful soup fails to acquire the prices at random often, in the form of empty lists in output. def getAmazonPrice(productUrl): elems = [] while elems == None …

Total answers: 1

Python requests: POST request dropping Authorization header

Python requests: POST request dropping Authorization header Question: I’m trying to make an API POST request using the Python requests library. I am passing through an Authorization header but when I try debugging, I can see that the header is being dropped. I have no idea what’s going on. Here’s my code: access_token = get_access_token() …

Total answers: 8

Pandas read_csv from URL and include request header

Pandas read_csv from URL and include request header Question: As of Pandas 0.19.2, the function read_csv() can be passed a URL. See, for example, from this answer: import pandas as pd url=”https://raw.githubusercontent.com/cs109/2014_data/master/countries.csv” c=pd.read_csv(url) The URL I’d like to use is: https://moz.com/top500/domains/csv With the above code, this URL returns an error: urllib2.HTTPError: HTTP Error 403: Forbidden …

Total answers: 2

Convert HTTP response code to text message with Python standard package

Convert HTTP response code to text message with Python standard package Question: This question is about the HTTP Response Codes. In my python application I want to present the user the text related to such a code. e.g. 404 would be Not Found. I checked the python docs but couldn’t found a package which give …

Total answers: 2

Set Unicode filename in Flask response header

Set Unicode filename in Flask response header Question: I am trying to set the Content-Disposition header to send a file to the client. The file name is Unicode. When I try to set the header, it fails with a UnicodeEncodeError. I tried various combinations of encode and decode but couldn’t get it to work. How …

Total answers: 1

how to determine the filename of content downloaded with HTTP in Python?

how to determine the filename of content downloaded with HTTP in Python? Question: I download a file using the get function of Python requests library. For storing the file, I’d like to determine the filename the way a web browser would for its ‘save’ or ‘save as …’ dialog. Easy, right? I can just get …

Total answers: 3