Requests giving me error with correct urlMaking a Python POST request having Java examplecannot write csv file with pythonImport error when using skvideo.ioHTTP Error 404: Not Found python urllibjson.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0) - Error only occurs when code is nestedTensorflow - 'Unable to get element as bytes' errorImporting tensorflow not working when upgradedDownloading Images with Urllib in Python 3.6.4Failed to establish a new connection Discord.py

What's it called when the bad guy gets eaten?

How do you move up one folder in Finder?

What were the main German words for a prostitute before 1800?

Swapping "Good" and "Bad"

How to drill holes in 3/8" thick steel plates?

For a hashing function like MD5, how similar can two plaintext strings be and still generate the same hash?

When an electron changes its spin, or any other intrinsic property, is it still the same electron?

Why did Harry Potter get a bedroom?

Shortest hex dumping program

How to know if blackberries are safe to eat

Can the Mage Hand cantrip be used to trip an enemy who is running away?

Killing Magic Numbers: "const int" vs "constexpr int" (or is there no difference in the end)

Historical experience as a guide to warship design?

What happens to unproductive professors?

Is there a strong legal guarantee that the U.S. can give to another country that it won't attack them?

Single word for "refusing to move to next activity unless present one is completed."

Credit score and financing new car

Why return a static pointer instead of an out parameter?

How can I fix the dull colors I am getting in Ubuntu 19.04 Terminal?

GDPR rights when subject dies; does family inherit subject rights?

Diagonal arrows (using TikZ) should be aligned in parallel

Managing and organizing the massively increased number of classes after switching to SOLID?

Is there any reason why MCU changed the Snap to Blip

How to say "How long have you had this dream?"



Requests giving me error with correct url


Making a Python POST request having Java examplecannot write csv file with pythonImport error when using skvideo.ioHTTP Error 404: Not Found python urllibjson.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0) - Error only occurs when code is nestedTensorflow - 'Unable to get element as bytes' errorImporting tensorflow not working when upgradedDownloading Images with Urllib in Python 3.6.4Failed to establish a new connection Discord.py






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








2















I am trying to search an API and when using the requests function I get an error that seems to indicate that there is nothing in JSON on the URL.When putting in my browser it works, and the function works in a similar piece of code.



This is my first ever time trying to code anything, so I getting to here was an effort but now I am just stuck and not sure where my error is. right now I am printing the URL, and when I put into my browser I find JSON code and the code works in another similar program I was making for testing.



import requests
import time

api = 'https://api.mojang.com/users/profiles/minecraft/'


f = open('Pokemon.txt', 'r')
for line in f:
url = (api + line)
print(url)

json_data = requests.get(url).json()
Result = (json_data)
print(result)




Here I get this back:



https://api.mojang.com/users/profiles/minecraft/Bulbasaur

Traceback (most recent call last):
File "C:UsersFierce-PCDesktopMC Name projectPokemon.py", line 12, in <module>
json_data = requests.get(url).json()
File "C:UsersFierce-PCAppDataLocalProgramsPythonPython36-32libsite-packagesrequestsmodels.py", line 897, in json
return complexjson.loads(self.text, **kwargs)
File "C:UsersFierce-PCAppDataLocalProgramsPythonPython36-32libjson__init__.py", line 354, in loads
return _default_decoder.decode(s)
File "C:UsersFierce-PCAppDataLocalProgramsPythonPython36-32libjsondecoder.py", line 339, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "C:UsersFierce-PCAppDataLocalProgramsPythonPython36-32libjsondecoder.py", line 357, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
>>>




You can clearly see that https://api.mojang.com/users/profiles/minecraft/Bulbasaur works if you click on it and it is in JSON format and I just don't really understand the problem.



What confused me more is that this code works



import urllib.parse
import requests

api = 'https://api.mojang.com/users/profiles/minecraft/'


Name = 'Bulbasaur'

url = (api + Name)
print(url)


json_data = requests.get(url).json()
print(json_data)


And it outputs this like I would want but it will not work with in the loop of looking through every Pokemon



'id': '06e299358e2f44f1ad8c5f859d63973b', 'name': 'Bulbasaur'


Sorry if this is a badly constructed post or that I am missing something really obvious.



EDIT: I edited both versions of the code to look like this:



 json_data = requests.get(url)
print(json_data)


And for the print on the second line on the version that works I get this back



<Response [200]>


Where as on my main not working program I get this:



<Response [204]>


This as far as I can tell indicates that my code is not working though I am not too sure of the fix still though










share|improve this question



















  • 1





    You might want to strip() the URL before making the request to get rid of the trailing new line.

    – dwagon
    Mar 26 at 1:29







  • 1





    i would always do the request.get() and validate that it worked by looking at status_code before moving on with the json. Assuming that a network request will always work is brave.

    – dwagon
    Mar 26 at 1:31











  • for line in f.readlines(): to iterate through the lines of a file

    – Jacques Gaudin
    Mar 26 at 1:38






  • 1





    @JacquesGaudin The for line in f is perfectly acceptable, and preferable in my opinion, since early python2 days as it increases readability.

    – dwagon
    Mar 26 at 1:46











  • @dwagon Really? Thanks a lot, I didn't know!

    – Jacques Gaudin
    Mar 26 at 1:48

















2















I am trying to search an API and when using the requests function I get an error that seems to indicate that there is nothing in JSON on the URL.When putting in my browser it works, and the function works in a similar piece of code.



This is my first ever time trying to code anything, so I getting to here was an effort but now I am just stuck and not sure where my error is. right now I am printing the URL, and when I put into my browser I find JSON code and the code works in another similar program I was making for testing.



import requests
import time

api = 'https://api.mojang.com/users/profiles/minecraft/'


f = open('Pokemon.txt', 'r')
for line in f:
url = (api + line)
print(url)

json_data = requests.get(url).json()
Result = (json_data)
print(result)




Here I get this back:



https://api.mojang.com/users/profiles/minecraft/Bulbasaur

Traceback (most recent call last):
File "C:UsersFierce-PCDesktopMC Name projectPokemon.py", line 12, in <module>
json_data = requests.get(url).json()
File "C:UsersFierce-PCAppDataLocalProgramsPythonPython36-32libsite-packagesrequestsmodels.py", line 897, in json
return complexjson.loads(self.text, **kwargs)
File "C:UsersFierce-PCAppDataLocalProgramsPythonPython36-32libjson__init__.py", line 354, in loads
return _default_decoder.decode(s)
File "C:UsersFierce-PCAppDataLocalProgramsPythonPython36-32libjsondecoder.py", line 339, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "C:UsersFierce-PCAppDataLocalProgramsPythonPython36-32libjsondecoder.py", line 357, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
>>>




You can clearly see that https://api.mojang.com/users/profiles/minecraft/Bulbasaur works if you click on it and it is in JSON format and I just don't really understand the problem.



What confused me more is that this code works



import urllib.parse
import requests

api = 'https://api.mojang.com/users/profiles/minecraft/'


Name = 'Bulbasaur'

url = (api + Name)
print(url)


json_data = requests.get(url).json()
print(json_data)


And it outputs this like I would want but it will not work with in the loop of looking through every Pokemon



'id': '06e299358e2f44f1ad8c5f859d63973b', 'name': 'Bulbasaur'


Sorry if this is a badly constructed post or that I am missing something really obvious.



EDIT: I edited both versions of the code to look like this:



 json_data = requests.get(url)
print(json_data)


And for the print on the second line on the version that works I get this back



<Response [200]>


Where as on my main not working program I get this:



<Response [204]>


This as far as I can tell indicates that my code is not working though I am not too sure of the fix still though










share|improve this question



















  • 1





    You might want to strip() the URL before making the request to get rid of the trailing new line.

    – dwagon
    Mar 26 at 1:29







  • 1





    i would always do the request.get() and validate that it worked by looking at status_code before moving on with the json. Assuming that a network request will always work is brave.

    – dwagon
    Mar 26 at 1:31











  • for line in f.readlines(): to iterate through the lines of a file

    – Jacques Gaudin
    Mar 26 at 1:38






  • 1





    @JacquesGaudin The for line in f is perfectly acceptable, and preferable in my opinion, since early python2 days as it increases readability.

    – dwagon
    Mar 26 at 1:46











  • @dwagon Really? Thanks a lot, I didn't know!

    – Jacques Gaudin
    Mar 26 at 1:48













2












2








2








I am trying to search an API and when using the requests function I get an error that seems to indicate that there is nothing in JSON on the URL.When putting in my browser it works, and the function works in a similar piece of code.



This is my first ever time trying to code anything, so I getting to here was an effort but now I am just stuck and not sure where my error is. right now I am printing the URL, and when I put into my browser I find JSON code and the code works in another similar program I was making for testing.



import requests
import time

api = 'https://api.mojang.com/users/profiles/minecraft/'


f = open('Pokemon.txt', 'r')
for line in f:
url = (api + line)
print(url)

json_data = requests.get(url).json()
Result = (json_data)
print(result)




Here I get this back:



https://api.mojang.com/users/profiles/minecraft/Bulbasaur

Traceback (most recent call last):
File "C:UsersFierce-PCDesktopMC Name projectPokemon.py", line 12, in <module>
json_data = requests.get(url).json()
File "C:UsersFierce-PCAppDataLocalProgramsPythonPython36-32libsite-packagesrequestsmodels.py", line 897, in json
return complexjson.loads(self.text, **kwargs)
File "C:UsersFierce-PCAppDataLocalProgramsPythonPython36-32libjson__init__.py", line 354, in loads
return _default_decoder.decode(s)
File "C:UsersFierce-PCAppDataLocalProgramsPythonPython36-32libjsondecoder.py", line 339, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "C:UsersFierce-PCAppDataLocalProgramsPythonPython36-32libjsondecoder.py", line 357, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
>>>




You can clearly see that https://api.mojang.com/users/profiles/minecraft/Bulbasaur works if you click on it and it is in JSON format and I just don't really understand the problem.



What confused me more is that this code works



import urllib.parse
import requests

api = 'https://api.mojang.com/users/profiles/minecraft/'


Name = 'Bulbasaur'

url = (api + Name)
print(url)


json_data = requests.get(url).json()
print(json_data)


And it outputs this like I would want but it will not work with in the loop of looking through every Pokemon



'id': '06e299358e2f44f1ad8c5f859d63973b', 'name': 'Bulbasaur'


Sorry if this is a badly constructed post or that I am missing something really obvious.



EDIT: I edited both versions of the code to look like this:



 json_data = requests.get(url)
print(json_data)


And for the print on the second line on the version that works I get this back



<Response [200]>


Where as on my main not working program I get this:



<Response [204]>


This as far as I can tell indicates that my code is not working though I am not too sure of the fix still though










share|improve this question
















I am trying to search an API and when using the requests function I get an error that seems to indicate that there is nothing in JSON on the URL.When putting in my browser it works, and the function works in a similar piece of code.



This is my first ever time trying to code anything, so I getting to here was an effort but now I am just stuck and not sure where my error is. right now I am printing the URL, and when I put into my browser I find JSON code and the code works in another similar program I was making for testing.



import requests
import time

api = 'https://api.mojang.com/users/profiles/minecraft/'


f = open('Pokemon.txt', 'r')
for line in f:
url = (api + line)
print(url)

json_data = requests.get(url).json()
Result = (json_data)
print(result)




Here I get this back:



https://api.mojang.com/users/profiles/minecraft/Bulbasaur

Traceback (most recent call last):
File "C:UsersFierce-PCDesktopMC Name projectPokemon.py", line 12, in <module>
json_data = requests.get(url).json()
File "C:UsersFierce-PCAppDataLocalProgramsPythonPython36-32libsite-packagesrequestsmodels.py", line 897, in json
return complexjson.loads(self.text, **kwargs)
File "C:UsersFierce-PCAppDataLocalProgramsPythonPython36-32libjson__init__.py", line 354, in loads
return _default_decoder.decode(s)
File "C:UsersFierce-PCAppDataLocalProgramsPythonPython36-32libjsondecoder.py", line 339, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "C:UsersFierce-PCAppDataLocalProgramsPythonPython36-32libjsondecoder.py", line 357, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
>>>




You can clearly see that https://api.mojang.com/users/profiles/minecraft/Bulbasaur works if you click on it and it is in JSON format and I just don't really understand the problem.



What confused me more is that this code works



import urllib.parse
import requests

api = 'https://api.mojang.com/users/profiles/minecraft/'


Name = 'Bulbasaur'

url = (api + Name)
print(url)


json_data = requests.get(url).json()
print(json_data)


And it outputs this like I would want but it will not work with in the loop of looking through every Pokemon



'id': '06e299358e2f44f1ad8c5f859d63973b', 'name': 'Bulbasaur'


Sorry if this is a badly constructed post or that I am missing something really obvious.



EDIT: I edited both versions of the code to look like this:



 json_data = requests.get(url)
print(json_data)


And for the print on the second line on the version that works I get this back



<Response [200]>


Where as on my main not working program I get this:



<Response [204]>


This as far as I can tell indicates that my code is not working though I am not too sure of the fix still though







python python-requests






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 26 at 2:03







joshua merrick

















asked Mar 26 at 1:28









joshua merrickjoshua merrick

133 bronze badges




133 bronze badges







  • 1





    You might want to strip() the URL before making the request to get rid of the trailing new line.

    – dwagon
    Mar 26 at 1:29







  • 1





    i would always do the request.get() and validate that it worked by looking at status_code before moving on with the json. Assuming that a network request will always work is brave.

    – dwagon
    Mar 26 at 1:31











  • for line in f.readlines(): to iterate through the lines of a file

    – Jacques Gaudin
    Mar 26 at 1:38






  • 1





    @JacquesGaudin The for line in f is perfectly acceptable, and preferable in my opinion, since early python2 days as it increases readability.

    – dwagon
    Mar 26 at 1:46











  • @dwagon Really? Thanks a lot, I didn't know!

    – Jacques Gaudin
    Mar 26 at 1:48












  • 1





    You might want to strip() the URL before making the request to get rid of the trailing new line.

    – dwagon
    Mar 26 at 1:29







  • 1





    i would always do the request.get() and validate that it worked by looking at status_code before moving on with the json. Assuming that a network request will always work is brave.

    – dwagon
    Mar 26 at 1:31











  • for line in f.readlines(): to iterate through the lines of a file

    – Jacques Gaudin
    Mar 26 at 1:38






  • 1





    @JacquesGaudin The for line in f is perfectly acceptable, and preferable in my opinion, since early python2 days as it increases readability.

    – dwagon
    Mar 26 at 1:46











  • @dwagon Really? Thanks a lot, I didn't know!

    – Jacques Gaudin
    Mar 26 at 1:48







1




1





You might want to strip() the URL before making the request to get rid of the trailing new line.

– dwagon
Mar 26 at 1:29






You might want to strip() the URL before making the request to get rid of the trailing new line.

– dwagon
Mar 26 at 1:29





1




1





i would always do the request.get() and validate that it worked by looking at status_code before moving on with the json. Assuming that a network request will always work is brave.

– dwagon
Mar 26 at 1:31





i would always do the request.get() and validate that it worked by looking at status_code before moving on with the json. Assuming that a network request will always work is brave.

– dwagon
Mar 26 at 1:31













for line in f.readlines(): to iterate through the lines of a file

– Jacques Gaudin
Mar 26 at 1:38





for line in f.readlines(): to iterate through the lines of a file

– Jacques Gaudin
Mar 26 at 1:38




1




1





@JacquesGaudin The for line in f is perfectly acceptable, and preferable in my opinion, since early python2 days as it increases readability.

– dwagon
Mar 26 at 1:46





@JacquesGaudin The for line in f is perfectly acceptable, and preferable in my opinion, since early python2 days as it increases readability.

– dwagon
Mar 26 at 1:46













@dwagon Really? Thanks a lot, I didn't know!

– Jacques Gaudin
Mar 26 at 1:48





@dwagon Really? Thanks a lot, I didn't know!

– Jacques Gaudin
Mar 26 at 1:48












1 Answer
1






active

oldest

votes


















0














Try this code. It iterates across the lines in your file, constructs the URL and then tries to get the data; on failure it should print the reason and keep going on the next line.



with open('Pokemon.txt') as fh:
for line in fh:
url = (api + line.strip())
print(url)

conn = requests.get(url)
if not conn.ok:
print("Failure on : ".format(url, conn.reason))
continue
result = conn.json()
print(result)





share|improve this answer























  • @dwango thanks a lot.

    – joshua merrick
    Mar 26 at 13:26










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55348612%2frequests-giving-me-error-with-correct-url%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














Try this code. It iterates across the lines in your file, constructs the URL and then tries to get the data; on failure it should print the reason and keep going on the next line.



with open('Pokemon.txt') as fh:
for line in fh:
url = (api + line.strip())
print(url)

conn = requests.get(url)
if not conn.ok:
print("Failure on : ".format(url, conn.reason))
continue
result = conn.json()
print(result)





share|improve this answer























  • @dwango thanks a lot.

    – joshua merrick
    Mar 26 at 13:26















0














Try this code. It iterates across the lines in your file, constructs the URL and then tries to get the data; on failure it should print the reason and keep going on the next line.



with open('Pokemon.txt') as fh:
for line in fh:
url = (api + line.strip())
print(url)

conn = requests.get(url)
if not conn.ok:
print("Failure on : ".format(url, conn.reason))
continue
result = conn.json()
print(result)





share|improve this answer























  • @dwango thanks a lot.

    – joshua merrick
    Mar 26 at 13:26













0












0








0







Try this code. It iterates across the lines in your file, constructs the URL and then tries to get the data; on failure it should print the reason and keep going on the next line.



with open('Pokemon.txt') as fh:
for line in fh:
url = (api + line.strip())
print(url)

conn = requests.get(url)
if not conn.ok:
print("Failure on : ".format(url, conn.reason))
continue
result = conn.json()
print(result)





share|improve this answer













Try this code. It iterates across the lines in your file, constructs the URL and then tries to get the data; on failure it should print the reason and keep going on the next line.



with open('Pokemon.txt') as fh:
for line in fh:
url = (api + line.strip())
print(url)

conn = requests.get(url)
if not conn.ok:
print("Failure on : ".format(url, conn.reason))
continue
result = conn.json()
print(result)






share|improve this answer












share|improve this answer



share|improve this answer










answered Mar 26 at 2:15









dwagondwagon

3983 silver badges9 bronze badges




3983 silver badges9 bronze badges












  • @dwango thanks a lot.

    – joshua merrick
    Mar 26 at 13:26

















  • @dwango thanks a lot.

    – joshua merrick
    Mar 26 at 13:26
















@dwango thanks a lot.

– joshua merrick
Mar 26 at 13:26





@dwango thanks a lot.

– joshua merrick
Mar 26 at 13:26








Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55348612%2frequests-giving-me-error-with-correct-url%23new-answer', 'question_page');

);

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







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript