TypeError: expected string or bytes-like object in Python
up vote
-1
down vote
favorite
I am currently breaking on the subjected break. What is this TypeError
, and how do I resolve it? What are the necessary amendments required in the code?
from urllib.request import urlretrieve
stoxxeu600_url = urllib.request.urlretrieve('https://www.stoxx.com/document/Indices/Current/HistoricalData/hbrbcpe.txt')
vstoxx_url = urllib.request.urlretrieve('https://www.stoxx.com/document/Indices/Current/HistoricalData/h_vstoxx.txt')
data_folder = 'data/' #Save file to local target destination.
stoxxeu600_filepath = data_folder + "stoxxeu600.txt"
vstoxx_filepath = data_folder + "vstoxx.txt"
urlretrieve(stoxxeu600_url,stoxxeu600_filepath)
This is the output:
File "/home/aryabhatta/anaconda3/lib/python3.6/urllib/parse.py", line 938, in splittype
match = _typeprog.match(url)
TypeError: expected string or bytes-like object
python
New contributor
add a comment |
up vote
-1
down vote
favorite
I am currently breaking on the subjected break. What is this TypeError
, and how do I resolve it? What are the necessary amendments required in the code?
from urllib.request import urlretrieve
stoxxeu600_url = urllib.request.urlretrieve('https://www.stoxx.com/document/Indices/Current/HistoricalData/hbrbcpe.txt')
vstoxx_url = urllib.request.urlretrieve('https://www.stoxx.com/document/Indices/Current/HistoricalData/h_vstoxx.txt')
data_folder = 'data/' #Save file to local target destination.
stoxxeu600_filepath = data_folder + "stoxxeu600.txt"
vstoxx_filepath = data_folder + "vstoxx.txt"
urlretrieve(stoxxeu600_url,stoxxeu600_filepath)
This is the output:
File "/home/aryabhatta/anaconda3/lib/python3.6/urllib/parse.py", line 938, in splittype
match = _typeprog.match(url)
TypeError: expected string or bytes-like object
python
New contributor
Please include the complete error message.
– DYZ
2 days ago
add a comment |
up vote
-1
down vote
favorite
up vote
-1
down vote
favorite
I am currently breaking on the subjected break. What is this TypeError
, and how do I resolve it? What are the necessary amendments required in the code?
from urllib.request import urlretrieve
stoxxeu600_url = urllib.request.urlretrieve('https://www.stoxx.com/document/Indices/Current/HistoricalData/hbrbcpe.txt')
vstoxx_url = urllib.request.urlretrieve('https://www.stoxx.com/document/Indices/Current/HistoricalData/h_vstoxx.txt')
data_folder = 'data/' #Save file to local target destination.
stoxxeu600_filepath = data_folder + "stoxxeu600.txt"
vstoxx_filepath = data_folder + "vstoxx.txt"
urlretrieve(stoxxeu600_url,stoxxeu600_filepath)
This is the output:
File "/home/aryabhatta/anaconda3/lib/python3.6/urllib/parse.py", line 938, in splittype
match = _typeprog.match(url)
TypeError: expected string or bytes-like object
python
New contributor
I am currently breaking on the subjected break. What is this TypeError
, and how do I resolve it? What are the necessary amendments required in the code?
from urllib.request import urlretrieve
stoxxeu600_url = urllib.request.urlretrieve('https://www.stoxx.com/document/Indices/Current/HistoricalData/hbrbcpe.txt')
vstoxx_url = urllib.request.urlretrieve('https://www.stoxx.com/document/Indices/Current/HistoricalData/h_vstoxx.txt')
data_folder = 'data/' #Save file to local target destination.
stoxxeu600_filepath = data_folder + "stoxxeu600.txt"
vstoxx_filepath = data_folder + "vstoxx.txt"
urlretrieve(stoxxeu600_url,stoxxeu600_filepath)
This is the output:
File "/home/aryabhatta/anaconda3/lib/python3.6/urllib/parse.py", line 938, in splittype
match = _typeprog.match(url)
TypeError: expected string or bytes-like object
python
python
New contributor
New contributor
edited 2 days ago
public static void main
7231321
7231321
New contributor
asked 2 days ago
Himanshu Doneria
62
62
New contributor
New contributor
Please include the complete error message.
– DYZ
2 days ago
add a comment |
Please include the complete error message.
– DYZ
2 days ago
Please include the complete error message.
– DYZ
2 days ago
Please include the complete error message.
– DYZ
2 days ago
add a comment |
2 Answers
2
active
oldest
votes
up vote
0
down vote
urlretrieve
wants a string as its first argument. So stoxxeu600_url
should be a string.
from urllib.request import urlretrieve
stoxxeu600_url = 'https://www.stoxx.com/document/Indices/Current/HistoricalData/hbrbcpe.txt'
data_folder = 'data/' #Save file to local target destination.
stoxxeu600_filepath = data_folder + "stoxxeu600.txt"
urlretrieve(stoxxeu600_url, stoxxeu600_filepath)
add a comment |
up vote
0
down vote
You can see from the documentation of urlretrieve()
that the method returns a tuple (filename, headers)
In your code, you first call urlretrieve()
and store it into stoxxeu600_url
stoxxeu600_url = urllib.request.urlretrieve('https://www.stoxx.com/document/Indices/Current/HistoricalData/hbrbcpe.txt')
stoxxeu600_url
now has (filename, headers)
returned by urlretrieve()
You then call urlretrieve()
again with stoxxeu600_url
which is a tuple, and not the str/byte object, that the method expects. Thereby, causing the TypeError.
urlretrieve(stoxxeu600_url,stoxxeu600_filepath)
To fix it, just set stoxxeu600_url
to the url and then call the method.
from urllib.request import urlretrieve
stoxxeu600_url = 'https://www.stoxx.com/document/Indices/Current/HistoricalData/hbrbcpe.txt'
stoxxeu600_filepath = "stoxxeu600.txt"
urlretrieve(stoxxeu600_url, filename=stoxxeu600_filepath)
Thanks for suggestion.
– Himanshu Doneria
2 days ago
@HimanshuDoneria mark as answered if that was what you were looking for
– Xnkr
2 days ago
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
urlretrieve
wants a string as its first argument. So stoxxeu600_url
should be a string.
from urllib.request import urlretrieve
stoxxeu600_url = 'https://www.stoxx.com/document/Indices/Current/HistoricalData/hbrbcpe.txt'
data_folder = 'data/' #Save file to local target destination.
stoxxeu600_filepath = data_folder + "stoxxeu600.txt"
urlretrieve(stoxxeu600_url, stoxxeu600_filepath)
add a comment |
up vote
0
down vote
urlretrieve
wants a string as its first argument. So stoxxeu600_url
should be a string.
from urllib.request import urlretrieve
stoxxeu600_url = 'https://www.stoxx.com/document/Indices/Current/HistoricalData/hbrbcpe.txt'
data_folder = 'data/' #Save file to local target destination.
stoxxeu600_filepath = data_folder + "stoxxeu600.txt"
urlretrieve(stoxxeu600_url, stoxxeu600_filepath)
add a comment |
up vote
0
down vote
up vote
0
down vote
urlretrieve
wants a string as its first argument. So stoxxeu600_url
should be a string.
from urllib.request import urlretrieve
stoxxeu600_url = 'https://www.stoxx.com/document/Indices/Current/HistoricalData/hbrbcpe.txt'
data_folder = 'data/' #Save file to local target destination.
stoxxeu600_filepath = data_folder + "stoxxeu600.txt"
urlretrieve(stoxxeu600_url, stoxxeu600_filepath)
urlretrieve
wants a string as its first argument. So stoxxeu600_url
should be a string.
from urllib.request import urlretrieve
stoxxeu600_url = 'https://www.stoxx.com/document/Indices/Current/HistoricalData/hbrbcpe.txt'
data_folder = 'data/' #Save file to local target destination.
stoxxeu600_filepath = data_folder + "stoxxeu600.txt"
urlretrieve(stoxxeu600_url, stoxxeu600_filepath)
answered 2 days ago
Rob Bricheno
1,57611
1,57611
add a comment |
add a comment |
up vote
0
down vote
You can see from the documentation of urlretrieve()
that the method returns a tuple (filename, headers)
In your code, you first call urlretrieve()
and store it into stoxxeu600_url
stoxxeu600_url = urllib.request.urlretrieve('https://www.stoxx.com/document/Indices/Current/HistoricalData/hbrbcpe.txt')
stoxxeu600_url
now has (filename, headers)
returned by urlretrieve()
You then call urlretrieve()
again with stoxxeu600_url
which is a tuple, and not the str/byte object, that the method expects. Thereby, causing the TypeError.
urlretrieve(stoxxeu600_url,stoxxeu600_filepath)
To fix it, just set stoxxeu600_url
to the url and then call the method.
from urllib.request import urlretrieve
stoxxeu600_url = 'https://www.stoxx.com/document/Indices/Current/HistoricalData/hbrbcpe.txt'
stoxxeu600_filepath = "stoxxeu600.txt"
urlretrieve(stoxxeu600_url, filename=stoxxeu600_filepath)
Thanks for suggestion.
– Himanshu Doneria
2 days ago
@HimanshuDoneria mark as answered if that was what you were looking for
– Xnkr
2 days ago
add a comment |
up vote
0
down vote
You can see from the documentation of urlretrieve()
that the method returns a tuple (filename, headers)
In your code, you first call urlretrieve()
and store it into stoxxeu600_url
stoxxeu600_url = urllib.request.urlretrieve('https://www.stoxx.com/document/Indices/Current/HistoricalData/hbrbcpe.txt')
stoxxeu600_url
now has (filename, headers)
returned by urlretrieve()
You then call urlretrieve()
again with stoxxeu600_url
which is a tuple, and not the str/byte object, that the method expects. Thereby, causing the TypeError.
urlretrieve(stoxxeu600_url,stoxxeu600_filepath)
To fix it, just set stoxxeu600_url
to the url and then call the method.
from urllib.request import urlretrieve
stoxxeu600_url = 'https://www.stoxx.com/document/Indices/Current/HistoricalData/hbrbcpe.txt'
stoxxeu600_filepath = "stoxxeu600.txt"
urlretrieve(stoxxeu600_url, filename=stoxxeu600_filepath)
Thanks for suggestion.
– Himanshu Doneria
2 days ago
@HimanshuDoneria mark as answered if that was what you were looking for
– Xnkr
2 days ago
add a comment |
up vote
0
down vote
up vote
0
down vote
You can see from the documentation of urlretrieve()
that the method returns a tuple (filename, headers)
In your code, you first call urlretrieve()
and store it into stoxxeu600_url
stoxxeu600_url = urllib.request.urlretrieve('https://www.stoxx.com/document/Indices/Current/HistoricalData/hbrbcpe.txt')
stoxxeu600_url
now has (filename, headers)
returned by urlretrieve()
You then call urlretrieve()
again with stoxxeu600_url
which is a tuple, and not the str/byte object, that the method expects. Thereby, causing the TypeError.
urlretrieve(stoxxeu600_url,stoxxeu600_filepath)
To fix it, just set stoxxeu600_url
to the url and then call the method.
from urllib.request import urlretrieve
stoxxeu600_url = 'https://www.stoxx.com/document/Indices/Current/HistoricalData/hbrbcpe.txt'
stoxxeu600_filepath = "stoxxeu600.txt"
urlretrieve(stoxxeu600_url, filename=stoxxeu600_filepath)
You can see from the documentation of urlretrieve()
that the method returns a tuple (filename, headers)
In your code, you first call urlretrieve()
and store it into stoxxeu600_url
stoxxeu600_url = urllib.request.urlretrieve('https://www.stoxx.com/document/Indices/Current/HistoricalData/hbrbcpe.txt')
stoxxeu600_url
now has (filename, headers)
returned by urlretrieve()
You then call urlretrieve()
again with stoxxeu600_url
which is a tuple, and not the str/byte object, that the method expects. Thereby, causing the TypeError.
urlretrieve(stoxxeu600_url,stoxxeu600_filepath)
To fix it, just set stoxxeu600_url
to the url and then call the method.
from urllib.request import urlretrieve
stoxxeu600_url = 'https://www.stoxx.com/document/Indices/Current/HistoricalData/hbrbcpe.txt'
stoxxeu600_filepath = "stoxxeu600.txt"
urlretrieve(stoxxeu600_url, filename=stoxxeu600_filepath)
answered 2 days ago
Xnkr
400313
400313
Thanks for suggestion.
– Himanshu Doneria
2 days ago
@HimanshuDoneria mark as answered if that was what you were looking for
– Xnkr
2 days ago
add a comment |
Thanks for suggestion.
– Himanshu Doneria
2 days ago
@HimanshuDoneria mark as answered if that was what you were looking for
– Xnkr
2 days ago
Thanks for suggestion.
– Himanshu Doneria
2 days ago
Thanks for suggestion.
– Himanshu Doneria
2 days ago
@HimanshuDoneria mark as answered if that was what you were looking for
– Xnkr
2 days ago
@HimanshuDoneria mark as answered if that was what you were looking for
– Xnkr
2 days ago
add a comment |
Himanshu Doneria is a new contributor. Be nice, and check out our Code of Conduct.
Himanshu Doneria is a new contributor. Be nice, and check out our Code of Conduct.
Himanshu Doneria is a new contributor. Be nice, and check out our Code of Conduct.
Himanshu Doneria is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53343136%2ftypeerror-expected-string-or-bytes-like-object-in-python%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Please include the complete error message.
– DYZ
2 days ago