Skip to content
Advertisement

Tag: urllib

Ubuntu 18.04 python 2.7 urllib request not getting data

I have this python script which works with no problem on ubuntu 16.04 But it wont get data in ubuntu 18.04, any idea what the problem could be? No errors. Output: Full code is here : https://github.com/papampi/nvOC_by_fullzero_Community_Release/blob/Dual-cuda/WTM_SWITCHER Answer Since you’re using the Requests library, you should use it on each API. Requests provides a method to extract JSON, so you

Python scraping website shows unknown url type: view-source

I am trying to do scraping in Python. Then, I want to scrape a stock-info website. But I failed, I don’t know why. It gives the error below: But when I used Chrome I can view the source code by right-click. Answer Try removing view-source: from your url_src, in essence: I think view-source: is Chrome specific (so Chrome knows to

Python3: JSON POST Request WITHOUT requests library

I want to send JSON encoded data to a server using only native Python libraries. I love requests but I simply can’t use it because I can’t use it on the machine which runs the script. I need to do it without. My server is a local WAMP server. I always get an urllib.error.HTTPError: HTTP Error 500: Internal Server Error

Only add to a dict if a condition is met

I am using urllib.urlencode to build web POST parameters, however there are a few values I only want to be added if a value other than None exists for them. That works fine, however if I make the orange variable optional, how can I prevent it from being added to the parameters? Something like this (pseudocode): I hope this was

How to urlencode a querystring in Python?

I am trying to urlencode this string before I submit. Answer You need to pass your parameters into urlencode() as either a mapping (dict), or a sequence of 2-tuples, like: Python 3 or above Use urllib.parse.urlencode: Note that this does not do url encoding in the commonly used sense (look at the output). For that use urllib.parse.quote_plus.

How do I catch a specific HTTP error in Python?

I have but what I end up is catching any kind of HTTP error. I want to catch only if the specified webpage doesn’t exist (404?). Answer Python 3 Python 2 Just catch HTTPError, handle it, and if it’s not Error 404, simply use raise to re-raise the exception. See the Python tutorial. Here is a complete example for Python

Can’t download YouTube video

I’m having trouble retrieving the YouTube video automatically. Here’s the code. The problem is the last part. download = urllib.request.urlopen(download_url).read() There’s an error message (thanks Wooble): Answer The code on the original question relies on several assumptions about the content of YouTube pages and URLs (expressed in constructs such as “url.split(‘something=’)[1]”) which may not always be true. I tested it

Advertisement