I have a Python project/code using the YouTube V3 API. Everything was working fine for over 2 years now, but suddenly I keep getting HttpError 404 for any request I make.
For example: HttpError 404 when requesting https://www.googleapis.com/youtube/v3/channels?alt=json&part=contentDetails%2Csnippet%2Cstatistics&key=AIzaSyCtyf8jToJowBEhpNL37UU3EjW0QhowXc4&forUsername=Chessexplained returned "Not Found"
The funny thing is, that if you open/click the link manually it works.
This is my code:
from apiclient.discovery import build
DEVELOPER_KEY = mykey
YOUTUBE_API_SERVICE_NAME = "youtube"
YOUTUBE_API_VERSION = "v3"
service = build(YOUTUBE_API_SERVICE_NAME, YOUTUBE_API_VERSION, developerKey=DEVELOPER_KEY)
request = service.channels().list(part = "contentDetails,snippet,statistics", forUsername=username)
Related
I need to extract data from reddit (subreddits, posts, comments etc). I'm using asyncpraw and following the documentation:
pip install asyncpraw
import asyncpraw
reddit = asyncpraw.Reddit(
client_id="my client id",
client_secret="my client secret",
user_agent="my user agent",
)
I then try to get 10 “hot” submissions from r/test:
subreddit = await reddit.subreddit("test")
async for submission in subreddit.hot(limit=10):
print(submission.title)
I get the following response:
ResponseException: received 401 HTTP response
This is one of the basic things you can do listed in the Quick Start section on the site, but I already got an error, even though I followed the instruction. I get this when I try to do other things as well and don't understand why.
I tried browsing the site and got no results. I also tried running the script in myTerminal instead of the colab notebook and got the following error:
async for submission in subreddit.hot(limit=10):
^
SyntaxError: invalid syntax
I'm trying to request the supported timezones in the IANA format for a user (in Java), and getting the following error:
Error code: RequestBroker--ParseUri
Error message: Syntax error at position 57 in 'TimeZoneStandard='microsoft.graph.timeZoneStandard'Iana'''.
GET https://graph.microsoft.com/v1.0/users/email#redacted.com/outlook/microsoft.graph.supportedTimeZones(TimeZoneStandard=microsoft.graph.timeZoneStandard'Iana')
SdkVersion : graph-java/v2.3.1
Authorization : [PII_REDACTED]
400 : Bad Request
[...]
Based on our test suit, the request was working fine 3 days ago, and started failing with that error yesterday. We haven't changed anything for a while on our implementation, so I'm a bit baffled. For the request I'm essentially doing the following:
final String url = requestBuilder.outlook()
.getRequestUrlWithAdditionalSegment("microsoft.graph.supportedTimeZones(TimeZoneStandard=microsoft.graph.timeZoneStandard'Iana')");
final OutlookUserSupportedTimeZonesCollectionRequestBuilder builder = new OutlookUserSupportedTimeZonesCollectionRequestBuilder(
url, requestBuilder.getClient(), null
);
IOutlookUserSupportedTimeZonesCollectionPage page = builder.buildRequest().get();
The reason I'm doing this instead of the standard:
final IOutlookUserSupportedTimeZonesCollectionPage page = requestBuilder.outlook()
.supportedTimeZones(TimeZoneStandard.IANA)
.buildRequest()
.get();
Is because this isn't working as expected, as described here: https://github.com/microsoftgraph/microsoft-graph-docs/issues/7594 (the issue is for C#, but happens in Java too).
What I notice is that the GET url looks fine, and works fine in the Graph Explorer using the /me endpoint instead of the /users endpoint. But the string in the error message looks modified:
'TimeZoneStandard='microsoft.graph.timeZoneStandard'Iana'''
If I'm not mistaken, the outer apostrophes are simply quoting done when printing the error message, but there are further apostrophes introduced after the = sign, which aren't present in the GET URI, which might be causing the syntax error. Still, I have no idea where those come from.
Any help or hint would be greatly appreciated!
I have modified the call something like this
https://graph.microsoft.com/v1.0/users/UPN/outlook/supportedTimeZones(TimeZoneStandard='Iana')
It worked for me.
The F# Saturn web framework fails on retrieving a value for GET method when acceptJson is a part of pipeline.
Below a sample code that I run to reproduce the issue:
let api = pipeline {
plug acceptJson
set_header "x-pipeline-type" "Api"
}
let apiRouter = router {
not_found_handler (setStatusCode 404 >=> text "Api 404")
pipe_through api
get "/test" (text "Hello world")
}
let appRouter = router {
forward "/api" apiRouter
}
appRouter is then added in the use_router section of the application code.
When I'm sending the request with a header Content-Type:application/json the response is "404 not found". But if I remove plug acceptJson from the api pipeline definition I get a correct response.
How to make Saturn work with the plug acceptJson?
I suspect 3615 is right - this seems similar to a problem I just solved yesterday after beating my head against the wall for a week. A request to my app (just a straight app from "dotnew new Saturn") from my browser was accepted. But a request to the same url from a test method returned a 404. It boiled down to the fact that the test request was missing an "Accept" header. When I added "Accept text/html", it worked. What I deduced from that is that, if the app can't find a content type that will be accepted according to the request, then it will report a 404. Your situation is the same - you're trying to return Json, but the request didn't include an "Accept application/json", so it can't find any page that the request would accept.
Of course, I could be wrong.
Got some URLs which I'm testing using the requests library. Example code can be found below:
page = requests.get(url)
print (page.status_code)
#output: 200
Some URLs returns a 404 status code when tested manually. Why is the output giving 200 then?
The programmer can define the status code manually. And it may have misled you.
the HTTP status code “200”, means is “file found.” if you redirect to another page, you will get 200 status code
So You do not let your request redirects.
r = requests.get('http://example.com/sdfsdfs', allow_redirects=False)
print(r.status_code)
I have incorporated Swagger in my application. I am trying to get a individual details through id by hitting the endpoint in swagger. But I am getting the following error
Controller
#RequestMapping(value = "/{clientId}/")
public ResponseEntity<ClientDto> getClientById(#ApiParam(name = "Client Id", required = true) #PathVariable("clientId") UUID clientId){}
Error
Error Code 400
connection: close
content-length: 0
date: Tue, 22 May 2018 12:56:40 GMT
It's working correctly in Postman but I don't know why I am facing this error in swagger. Can somebody help me out from this?
I found out the reason for the issue.
The URL that I am trying to hit is
#RequestMapping(value = "/{clientId}/")
public ResponseEntity<ClientDto> getClientById(#ApiParam(name = "Client Id", required = true) #PathVariable("clientId") UUID clientId){}
I thought the name parameter in the #ApiParam is just used for display purpose in the swagger-UI but now I realized that it should match with value parameter in the #RequestMapping
I have changed the code from
#ApiParam(name="Client Id") to #ApiParam(name="clientId")