I extremely new to python and practicing Loading a dataset from a url.
When running the following code:
In [1]: myUrl = "http://aima.cs.berkeley.edu/data/iris.csv"
In [2]: urlRequest = urllib.request.Request(myUrl)
I get this error:
File "", line 1, in
urlRequest = urllib.request.Request(myUrl)
AttributeError: 'module' object has no attribute 'request'
1) I tried researching this error and attempted to use import urllib3 again and it imported fine. However when attempting the request I get that error...
2) I attempted to get "help" help("urllib3") in python 3.6.0 and got:
No Python documentation found for 'urllib3'. Use help() to get the
interactive help utility. Use help(str) for help on the str class.
3) I searched Stackoverflow and saw a similar question; tried the suggestions and was not able to move past that line of code...
Am I doing something wrong here?
Thanks in advance for your time
From what I see "request" is not a package, meaning that you can't directly import classes from it.
try :
from urllib.request import Request
myUrl = "http://aima.cs.berkeley.edu/data/iris.csv"
urlRequest = Request(myUrl)
Related
I am importing the data set set and getting the above warning and not able to understand which function is causing this warning.
DeprecationWarning: You are using the post() function from 'ibm_botocore.vendored.requests'. This is not a public API in ibm_botocore and will be removed in the future. Additionally, this version of requests is out of date. We recommend you install the requests package, 'import requests' directly, and use the requests.post() function instead.
Code
import types
import pandas as pd
from botocore.client import Config
import ibm_boto3
def __iter__(self): return 0
client_cbe8a2731f0140ccb1120588edd17f92 = ibm_boto3.client(service_name='s3',
ibm_api_key_id='xxx',
ibm_auth_endpoint="https://yy",
config=Config(signature_version='oauth'),
endpoint_url='https://zz.com')
body = `enter code here`client_cbe8a2731f0140ccb1120588edd17f92.get_object(Bucket='abc',Key='data.csv')['Body']
# add missing __iter__ method, so pandas accepts body as file-like object
if not hasattr(body, "__iter__"): body.__iter__ = types.MethodType( __iter__, body )
data = pd.read_csv(body)
Try shutting down and restarting your Kernel. I was running in a Jupyter Notebook with the identical issue. Shutdown/Restart seemed to resolve!
Update... I must have been lucky. I am still seeing this message randomly. I can not discern any pattern.
I'm starting learning basic feature extraction with librosa and was trying reading and storing ten kick drums with pathlib, but it doesn't work since I always getting an encoding error, where as there is no error without pathlib.
I tried changing the path, updating every imported library very often, using wav instead of mp3 but had no further idea.
My code:
%matplotlib inline
from pathlib import Path
import numpy, scipy, matplotlib.pyplot as plt, sklearn, urllib, IPython.display as ipd
import librosa, librosa.display
kick_signals = [
librosa.load(p)[0] for p in Path().glob('audio/drum_samples/train/kick_*.mp3')
]
Error messages:
RuntimeError: Error opening 'audio/techno-nine_o_three.mp3': File contains data in an unknown format.
and
AttributeError: 'PosixPath' object has no attribute 'encode'
I would be very thankful, if you would and could help me.
You can convert the PossixPath object to a string, using p.as_posix()
Example:
p = Path(file_path)
p.as_posix()
Try:
kick_signals = [
librosa.load(p.absolute())[0] for p in Path().glob('audio/drum_samples/train/kick_*.mp3')
]
That way you pass a string instead of a PosixPath to librosa.
If that does not fix it, check your mp3 file. Does it play in a regular player? If not, please post the whole error message (stacktrace). Perhaps librosa's dependencies aren't installed properly.
I get this error:
invalid syntax (<unknown>, line 4)pylint(syntax-error)
Invalid syntax on result on the fourth line.
import requests
from bs4 import BeautifulSoup
result = requests.get(https://www.google.com/)
result.status_code == requests.codes.ok
Before all, you should consider using a real IDE to write your code (like Eclipse/Pydev, Pycharm or VSCode), it would help you avoiding those kind of mistakes.
You are missing the quotes around your URL:
result = requests.get("https://www.google.com/")
I am trying to create an app to access Etsy api using python3, I am testing my very basic code in idle3, I need to get an oauth token, I have looked at the etsy documentation here but all is described for php.
below is my code in idle3 (I have changed my keys);
>>>payload = { 'api_key' : 'pvhkg9y4e7', 'shared_secret' : 'ib5msimmo', 'scope' : 'transactions_r,listings_w,billing_r,treasury_r'}
>>> url = "https://openapi.etsy.com/v2/oauth/request_token"
>>> r = requests.get(url, params=payload)
>>> print(r.url)
https://openapi.etsy.com/v2/oauth/request_token?api_key=pvhkg9y4e7&scope=transactions_r%2Clistings_w%2Cbilling_r%2Ctreasury_r&shared_secret=ib5msimmo
>>> r.text
>>>'oauth_problem=parameter_absent&oauth_parameters_absent=oauth_consumer_key%26oauth_signature%26oauth_signature_method%26oauth_nonce%26oauth_timestamp
I need help in creating the correct URL I think I need to change my payload wording to oauth_consumer_key, oauth_signature, but I do not understand how to include oauth_signature_method (I am using request.get) or the oauth_timestamp, and I don't know what oauth_nonce is?
I intend to incorporate the whole into a flask app, so I have looked at flask_oauth here but I am not sure if this will give me the timestamp and nonce.
All advice greatly appreciated, I am following the flask tutorial by miguel grinberg, I need one like that for my etsy app! any suggestions
I also tried request_oauthlib but got this;
>>> from requests_oauthlib import OAuth1
>>>Traceback (most recent call last):
File "<pyshell#15>", line 1, in <module>
from requests_oauthlib import OAuth1
ImportError: No module named 'requests_oauthlib'
Regards
Paul
I wrote to etsy developers, who came back with some php code, I know very little python but no PHP,
So I went back to searching google, and went back to here and used the following code;
import requests
from requests_oauthlib import OAuth1
request_token_url = 'https://openapi.etsy.com/v2/oauth/request_token?scope=transactions_r&listings_w&billing_r&treasury_r'
consumer_key = 'api_key'
consumer_secret = 'secret_key'
oauth = OAuth1(consumer_key, client_secret=consumer_secret)
r = requests.post(url=request_token_url, auth=oauth)
r.content
login_url=https%6%3fthe%26address%26you%2fwant%34goodluck
and it worked!!!!!! I am so happpppy!!!
If you get any other noobs like me perhaps they can be help them with this code.
In terminal I created a virtualenv, I then pip installed requests and request_oauthlib, then in python shell executed the above script.
regards paul
So, as a replacement for mechanize because Visual Studio "needs" python 3.4, and mechanize isn't compatible with 3.4, I found "robobrowser" as a replacement, but I'm having trouble trying to figure out why browser.open returns "AttributeError: 'module' object has no attribute 'open'"
import re
from robobrowser import browser
import time
br = browser
br.open("Website")
br.select_form(name="game-pin-input")
print ("Enter the game pin")
response = br.submit()
time.sleep(3)
Any suggestions, or replacements?
Edit: The Documentation can be found here, and "open" is valid.
https://robobrowser.readthedocs.org/en/latest/api.html#module-robobrowser.browser
I'm guessing browser is a module; according to the docs, you wanted RoboBrowser, and you need to construct an instance before open-ing anything. To roughly match your code:
from robobrowser import RoboBrowser
# Browse to Genius
br = RoboBrowser(history=True) # No idea if history matters
br.open("Website")
I'm guessing robobrowser.browser is some implementation internal module that is importable, but not at all what you wanted.
Update: According to your own docs link, robobrowser.browser is just a module, and RoboBrowser is the class you needed, confirming my earlier statement (RoboBrowser is probably exposed on robobrowser itself for convenience).