urllib

URLError: <urlopen error [SSL: UNSAFE_LEGACY_RENEGOTIATION_DISABLED] unsafe legacy renegotiation disabled (_ssl.c:1007)>

URLError: <urlopen error [SSL: UNSAFE_LEGACY_RENEGOTIATION_DISABLED] unsafe legacy renegotiation disabled (_ssl.c:1007)> Question: I’m trying to retrieve audio files via URLs retrieved from conllu files. I receive the link, but when I want to download the file, I get the following error, while when I enter the link on the browser I manage to download the file, …

Total answers: 1

urllib: TypeError: expected string or bytes-like object

urllib: TypeError: expected string or bytes-like object Question: I am trying to make an API call where I pass a file in the header import urllib.request headers = {‘files[]’: open(‘File.sql’,’rb’)} datagen ={} request = urllib.request.Request(‘https://www.rebasedata.com/api/v1/convert’, datagen, headers) response1 = urllib.request.urlopen(request) # Error : TypeError: expected string or bytes-like object response2 = urllib.request.urlopen(‘https://www.rebasedata.com/api/v1/convert’, datagen, headers) #Error: …

Total answers: 2

Parse GET parameters

Parse GET parameters Question: I have an REST API where the url looks like this: class RRervice(pyrestful.rest.RestHandler): @get(‘/Indicator/{rparms}’) def RR(self, rparms): print(rparms) … So when this codes executes on this URL: http://ip:3000/Indicator/thresh=.8&symbol=AAPL The print I get what I am supposed to get: thresh=.8&symbol=AAPL My question is, is there an API that ensures that certain parameters …

Total answers: 1

Cyrillic Encoding in Urllib Python with lower cases

Cyrillic Encoding in Urllib Python with lower cases Question: My goal is to encode this dict with cyrilic text: target_dict = {"Animal": "Cat", "city": "Москва"} To this (cyrilic lettesrs with lower case encoded): Animal=Cat&city=%d0%9c%d0%be%d1%81%d0%ba%d0%b2%d0%b0 By default with python it encodes with UPPER CASE, this is my code: import urllib.parse target_dict = {"Animal": "Cat", "city": "Москва"} …

Total answers: 1

Word count script in Python

Word count script in Python Question: Can someone please explain me why there is ‘b’ in front of each word and how to get read of it? Script returns something like this: word= b’yesterday,’ , count = 3 current_word = {} current_count = 0 text = "https://raw.githubusercontent.com/KseniaGiansar/pythonProject2_text/master/yesterday.txt" request = urllib.request.urlopen(text) each_word = [] words = …

Total answers: 3

How to continue other link when Urllib 404 error

How to continue other link when Urllib 404 error Question: I’m trying to download images from a csv with lot of links. Works fine until some link is broken (urllib.error.HTTPError: HTTP Error 404: Not Found) . import pandas as pd import urllib.request import urllib.error opener = urllib.request.build_opener() def url_to_jpg (i,url,file_path) : filename="image-{}".format(i) full_path = "{}{}".format(file_path, …

Total answers: 1

urllib.requiest.urlopen error: certificate verify failed on python Virtual Environment

urllib.requiest.urlopen error: certificate verify failed on python Virtual Environment Question: Im building a Web Scapper, when testing on venv -> [SSL: CERTIFICATE_VERIFY_FAILED] But, when I’m testing on ipython shell -> Perfectly good I wondering what the root problem is? Thanks for your help!`from urllib.request import urlopen from bs4 import BeautifulSoup import subprocess html = urlopen(‘http://www.pythonscraping.com/pages/page3.html’) …

Total answers: 2

urllib: specifying download path makes url invalid

urllib: specifying download path makes url invalid Question: I am trying to write a function that takes a url and a path and downloads a file to that path IF it’s a text file. import urllib import re import os mcBethURL = ‘https://ia802707.us.archive.org/1/items/macbeth02264gut/0ws3410.txt’ def download_file(url, path, local_filename): try: url_type = urllib.request.urlopen(url).info()[‘content-type’] if bool(re.search(‘t[e]*xt’, url_type)): local_filename …

Total answers: 1

Stop urllib.request from raising exceptions on HTTP errors

Stop urllib.request from raising exceptions on HTTP errors Question: Python’s urllib.request.urlopen() will raise an exception if the HTTP status code of the request is not OK (e.g., 404). This is because the default opener uses the HTTPDefaultErrorHandler class: A class which defines a default handler for HTTP error responses; all responses are turned into HTTPError …

Total answers: 1

pb avec web scraping

pb avec web scraping Question: import requests import pandas as pd from urllib.request import urlopen from bs4 import BeautifulSoup df = [] for x in range(1,31): url_allocine= ‘https://www.allocine.fr/film/meilleurs/?page=’ page = requests.get(url_allocine + str(x)) soup = BeautifulSoup(page.content, ‘html.parser’) films_all = soup.findAll(‘div’,{‘class’:’card entity-card entity-card-list cf’}) #print(len(films_all)) film = films_all[0] #print(film) titre = film.find("div",{‘class’:’meta’}).find(‘a’).text #print(titre) note = film.findAll("div",{‘class’:’rating-item’})[0] …

Total answers: 2