laravel5.3 restful controller show MethodNotAllowedHttpException - laravel-5.3

1.Create a controller.
php artisan make:controller PhotoController --resource
2.Add a route in /routes/web.php.
Route::resource('photos', 'PhotoController');
3.Open postman using the DELETE method.
MethodNotAllowedHttpException in RouteCollection.php line 218:
in RouteCollection.php line 218
at RouteCollection->methodNotAllowed(array('GET', 'HEAD', 'POST')) in RouteCollection.php line 205
at RouteCollection->getRouteForMethods(object(Request), array('GET', 'HEAD', 'POST')) in RouteCollection.php line 158
at RouteCollection->match(object(Request)) in Router.php line 766
at Router->findRoute(object(Request)) in Router.php line 621
at Router->dispatchToRoute(object(Request)) in Router.php line 607
at Router->dispatch(object(Request)) in Kernel.php line 268
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request)) in Pipeline.php line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in CheckForMaintenanceMode.php line 46
at CheckForMaintenanceMode->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in Pipeline.php line 104
at Pipeline->then(object(Closure)) in Kernel.php line 150
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 117
at Kernel->handle(object(Request)) in index.php line 54

You are using the wrong HTTP method for the URI you are requesting. It is a simple as that.
What ever the VERB the ROUTE is defined as, is the VERB you have to use.
If a route is defined for POST, you have to use a POST method. If it is PUT you have to use PUT method, etc .....

Related

How do I troubleshoot a problem on the route between my machine and Google Cloud API?

I have a simple application that uses Google Cloud Pub/Sub, and as of a few days ago it has ceased working. Whenever I try to interact with the service (create a topic, subscribe to a topic, etc), I receive a DeadlineExceeded: 504 Deadline Exceeded error. For example:
from google.cloud import pubsub_v1
client = pubsub_v1.PublisherClient()
client.create_topic(request={"name": "test_topic"})
I have tried:
Creating new service account credentials
Lowering security on my Xfinity/Comcast router
The one thing that worked temporarily was a factory reset of the router, but then an hour later it stopped working.
Also, this problem exists across all the Python libraries for Google Cloud.
I am quite unfamiliar with networking so don't even know where to begin to solve this problem. Thanks in advance.
EDIT:
Full error
In [14]: from google.cloud import pubsub_v1
...: client = pubsub_v1.PublisherClient()
...: client.create_topic(request={"name": "test_topic"})
---------------------------------------------------------------------------
_InactiveRpcError Traceback (most recent call last)
~/anaconda3/envs/testvenv/lib/python3.8/site-packages/google/api_core/grpc_helpers.py in error_remapped_callable(*args, **kwargs)
66 try:
---> 67 return callable_(*args, **kwargs)
68 except grpc.RpcError as exc:
~/anaconda3/envs/testvenv/lib/python3.8/site-packages/grpc/_channel.py in __call__(self, request, timeout, metadata, credentials, wait_for_ready, compression)
945 wait_for_ready, compression)
--> 946 return _end_unary_response_blocking(state, call, False, None)
947
~/anaconda3/envs/testvenv/lib/python3.8/site-packages/grpc/_channel.py in _end_unary_response_blocking(state, call, with_call, deadline)
848 else:
--> 849 raise _InactiveRpcError(state)
850
_InactiveRpcError: <_InactiveRpcError of RPC that terminated with:
status = StatusCode.DEADLINE_EXCEEDED
details = "Deadline Exceeded"
debug_error_string = "{"created":"#1634864865.356495000","description":"Deadline Exceeded","file":"src/core/ext/filters/deadline/deadline_filter.cc","file_line":81,"grpc_status":4}"
>
The above exception was the direct cause of the following exception:
DeadlineExceeded Traceback (most recent call last)
<ipython-input-14-e6f64ca6ba79> in <module>
1 from google.cloud import pubsub_v1
2 client = pubsub_v1.PublisherClient()
----> 3 client.create_topic(request={"name": "test_topic"})
~/anaconda3/envs/testvenv/lib/python3.8/site-packages/google/cloud/pubsub_v1/_gapic.py in <lambda>(self, *a, **kw)
38 return staticmethod(functools.wraps(wrapped_fx)(fx))
39 else:
---> 40 fx = lambda self, *a, **kw: wrapped_fx(self.api, *a, **kw) # noqa
41 return functools.wraps(wrapped_fx)(fx)
42
~/anaconda3/envs/testvenv/lib/python3.8/site-packages/google/pubsub_v1/services/publisher/client.py in create_topic(self, request, name, retry, timeout, metadata)
479
480 # Send the request.
--> 481 response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,)
482
483 # Done; return the response.
~/anaconda3/envs/testvenv/lib/python3.8/site-packages/google/api_core/gapic_v1/method.py in __call__(self, *args, **kwargs)
143 kwargs["metadata"] = metadata
144
--> 145 return wrapped_func(*args, **kwargs)
146
147
~/anaconda3/envs/testvenv/lib/python3.8/site-packages/google/api_core/retry.py in retry_wrapped_func(*args, **kwargs)
284 self._initial, self._maximum, multiplier=self._multiplier
285 )
--> 286 return retry_target(
287 target,
288 self._predicate,
~/anaconda3/envs/testvenv/lib/python3.8/site-packages/google/api_core/retry.py in retry_target(target, predicate, sleep_generator, deadline, on_error)
187 for sleep in sleep_generator:
188 try:
--> 189 return target()
190
191 # pylint: disable=broad-except
~/anaconda3/envs/testvenv/lib/python3.8/site-packages/google/api_core/timeout.py in func_with_timeout(*args, **kwargs)
100 """Wrapped function that adds timeout."""
101 kwargs["timeout"] = self._timeout
--> 102 return func(*args, **kwargs)
103
104 return func_with_timeout
~/anaconda3/envs/testvenv/lib/python3.8/site-packages/google/api_core/grpc_helpers.py in error_remapped_callable(*args, **kwargs)
67 return callable_(*args, **kwargs)
68 except grpc.RpcError as exc:
---> 69 six.raise_from(exceptions.from_grpc_error(exc), exc)
70
71 return error_remapped_callable
~/anaconda3/envs/testvenv/lib/python3.8/site-packages/six.py in raise_from(value, from_value)
DeadlineExceeded: 504 Deadline Exceeded
EDIT 2:
Operating system: macOS
Software firewall: Checked Network settings on my box and the firewall is turned off
Anti-virus software: None
Location: Chicago, USA
Region: Unsure what region my request would go to as it isn't specified
Also, I used my phone as a hotspot and I was able to connect to GCP.

jupyter notebook seaborn load_dataset https error: 404 not found [duplicate]

This question already has answers here:
Seaborn load_dataset
(4 answers)
why is jupyter notebook not accepting my csv file link? [duplicate]
(1 answer)
Closed last month.
Hi I'm a student looking to use jupyter notebook to represent a dataset for a school task.
import seaborn as sns
spotify = sns.load_dataset('top10s.csv')
this is a data set that I found online and when I try to run this code I get and HTTPError
---------------------------------------------------------------------------
HTTPError Traceback (most recent call last)
<ipython-input-2-af1fc80c3c1b> in <module>
1 import seaborn as sns
----> 2 spotify = sns.load_dataset('top10s.csv')
~\Anaconda3\lib\site-packages\seaborn\utils.py in load_dataset(name, cache, data_home, **kws)
426 os.path.basename(full_path))
427 if not os.path.exists(cache_path):
--> 428 urlretrieve(full_path, cache_path)
429 full_path = cache_path
430
~\Anaconda3\lib\urllib\request.py in urlretrieve(url, filename, reporthook, data)
245 url_type, path = splittype(url)
246
--> 247 with contextlib.closing(urlopen(url, data)) as fp:
248 headers = fp.info()
249
~\Anaconda3\lib\urllib\request.py in urlopen(url, data, timeout, cafile, capath, cadefault, context)
220 else:
221 opener = _opener
--> 222 return opener.open(url, data, timeout)
223
224 def install_opener(opener):
~\Anaconda3\lib\urllib\request.py in open(self, fullurl, data, timeout)
529 for processor in self.process_response.get(protocol, []):
530 meth = getattr(processor, meth_name)
--> 531 response = meth(req, response)
532
533 return response
~\Anaconda3\lib\urllib\request.py in http_response(self, request, response)
639 if not (200 <= code < 300):
640 response = self.parent.error(
--> 641 'http', request, response, code, msg, hdrs)
642
643 return response
~\Anaconda3\lib\urllib\request.py in error(self, proto, *args)
567 if http_err:
568 args = (dict, 'default', 'http_error_default') + orig_args
--> 569 return self._call_chain(*args)
570
571 # XXX probably also want an abstract factory that knows when it makes
~\Anaconda3\lib\urllib\request.py in _call_chain(self, chain, kind, meth_name, *args)
501 for handler in handlers:
502 func = getattr(handler, meth_name)
--> 503 result = func(*args)
504 if result is not None:
505 return result
~\Anaconda3\lib\urllib\request.py in http_error_default(self, req, fp, code, msg, hdrs)
647 class HTTPDefaultErrorHandler(BaseHandler):
648 def http_error_default(self, req, fp, code, msg, hdrs):
--> 649 raise HTTPError(req.full_url, code, msg, hdrs, fp)
650
651 class HTTPRedirectHandler(BaseHandler):
HTTPError: HTTP Error 404: Not Found
I do not know how to fix this
or why I am even getting is issue
I hope somebody can help me
and thank you for your time
There are 2 errors in the code.
We can load only datasets present in the seaborn website using sns.load_dataset as it for online CSV files on https://github.com/mwaskom/seaborn-data.
While specifying the dataset name no need to specify the extension of the dataset. Below is the sample code to load tips dataset.
import seaborn as sns
tips = sns.load_dataset("tips")
tips.head()
sns.load_dataset() searches for a dataset from online. It does not import the dataset from your working directory.
Here is the documentation for seaborn load_dataset function
Assuming that your dataset top10s.csv is located in the same folder as your python file, you should use pandas for this instead.
import pandas as pd
spotify = pd.read_csv('top10s.csv')
Be aware that you have to install this library before importing via pip like so:
pip install pandas
You'll need to install the latest master branch of zipline. You can do that by:
pip install zipline

telegram bot - Chat not found

I am totally new to telegram_bot. I want to execute a bot.send_message() in the following code (as commented in the code), but can't do so. Please help.
!pip install python-telegram-bot --upgrade
import telegram
bot = telegram.Bot(token='**************')
bot.send_message(chat_id='******', text="I'm sorry Dave I'm afraid I can't do that.")
It errors out as :
1 bot.send_message('mardepbot',"I'm sorry Dave I'm afraid I can't do that.")
/usr/local/lib/python3.6/dist-packages/telegram/bot.py in decorator(self, *args, **kwargs)
63 def decorator(self, *args, **kwargs):
64 logger.debug('Entering: %s', func.__name__)
---> 65 result = func(self, *args, **kwargs)
66 logger.debug(result)
67 logger.debug('Exiting: %s', func.__name__)
/usr/local/lib/python3.6/dist-packages/telegram/bot.py in decorator(self, *args, **kwargs)
88 data['reply_markup'] = reply_markup
89
---> 90 result = self._request.post(url, data, timeout=kwargs.get('timeout'))
91
92 if result is True:
/usr/local/lib/python3.6/dist-packages/telegram/utils/request.py in post(self, url, data, timeout)
307 result = self._request_wrapper('POST', url,
308 body=json.dumps(data).encode('utf-8'),
--> 309 headers={'Content-Type': 'application/json'})
310
311 return self._parse(result)
/usr/local/lib/python3.6/dist-packages/telegram/utils/request.py in _request_wrapper(self, *args, **kwargs)
221 raise Unauthorized(message)
222 elif resp.status == 400:
--> 223 raise BadRequest(message)
224 elif resp.status == 404:
225 raise InvalidToken()
BadRequest: Chat not found
I just solved the similar issue. Please check:
Your bot settings Group Privacy must be OFF (Bot Father -> Group Privacy -> disable).
If your bot has been already added to chat, delete it, and re-add
Make sure, there is a '-' sign before your chat id, so if your chat link looks like: https://web.telegram.org/#/im?p=g123456789, then your chat_id = '-123456789'
You can't send a message to a string ('mardepbot') as address. If mardepbot is the bot, you are using, then you made 2 errors; then you should use your own ID to send a message to yourself.

NotFoundHttpException in RouteCollection.php line 161 resource controller

I am using following code in routes/web.php
Route::resource('affiliate/account', 'Affiliate\AccountController',
[
'pSignup' => 'affiliate.signup',
'gSettings' => 'affiliate.settings'
]
);
Controller is in app/Http/Controllers/Affiliate/AccountController.php
I am getting following error.
NotFoundHttpException in RouteCollection.php line 161
Any suggestions, what is causing this error?

Symfony 2: The template should be a string or extend TemplateReference

I have not found any significant help regarding the "The template should be a string or extend TemplateReference" in my Symfony2 project, so I am wondering if there is someone around, who came across the above issue.
Stack Trace:
InvalidArgumentException: The template should be a string or extend TemplateReference
at n/a
in /home/test/apps/test_admin/dev/vendor/friendsofsymfony/rest-bundle/FOS/RestBundle/View/View.php line 178
at FOS\RestBundle\View\View->setTemplate(object(Template))
in /home/test/apps/test_admin/dev/vendor/friendsofsymfony/rest-bundle/FOS/RestBundle/EventListener/ViewResponseListener.php line 128
at FOS\RestBundle\EventListener\ViewResponseListener->onKernelView(object(GetResponseForControllerResultEvent))
in line
at call_user_func(array(object(ViewResponseListener), 'onKernelView'), object(GetResponseForControllerResultEvent))
in /home/test/apps/test_admin/dev/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Debug/TraceableEventDispatcher.php line 460
at Symfony\Component\HttpKernel\Debug\TraceableEventDispatcher->Symfony\Component\HttpKernel\Debug\{closure}(object(GetResponseForControllerResultEvent))
in line
at call_user_func(object(Closure), object(GetResponseForControllerResultEvent))
in /home/test/apps/test_admin/dev/app/cache/dev/classes.php line 1656
at Symfony\Component\EventDispatcher\EventDispatcher->doDispatch(array(object(Closure)), 'kernel.view', object(GetResponseForControllerResultEvent))
in /home/test/apps/test_admin/dev/app/cache/dev/classes.php line 1589
at Symfony\Component\EventDispatcher\EventDispatcher->dispatch('kernel.view', object(GetResponseForControllerResultEvent))
in /home/test/apps/test_admin/dev/app/cache/dev/classes.php line 1753
at Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch('kernel.view', object(GetResponseForControllerResultEvent))
in /home/test/apps/test_admin/dev/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Debug/TraceableEventDispatcher.php line 139
at Symfony\Component\HttpKernel\Debug\TraceableEventDispatcher->dispatch('kernel.view', object(GetResponseForControllerResultEvent))
in /home/test/apps/test_admin/dev/app/bootstrap.php.cache line 2906
at Symfony\Component\HttpKernel\HttpKernel->handleRaw(object(Request), '1')
in /home/test/apps/test_admin/dev/app/bootstrap.php.cache line 2877
at Symfony\Component\HttpKernel\HttpKernel->handle(object(Request), '1', true)
in /home/test/apps/test_admin/dev/app/bootstrap.php.cache line 3006
at Symfony\Component\HttpKernel\DependencyInjection\ContainerAwareHttpKernel->handle(object(Request), '1', true)
in /home/test/apps/test_admin/dev/app/bootstrap.php.cache line 2286
at Symfony\Component\HttpKernel\Kernel->handle(object(Request))
in /home/test/apps/test_admin/dev/web/app_dev.php line 28
UPDATE
I applied the following fix, but still no luck:
https://github.com/FriendsOfSymfony/FOSRestBundle/commit/d2e9aaca8128bfcbd7cd0cb8a80ae34ab71b0c7e
OK, I got this one sorted out.
So, the issue was that my FOSRestBundle dependency was not up-to-date. Therefore, as soon as I updated it the problem got resolved.
Thanks all for your interest to help me. :)

Resources